summaryrefslogblamecommitdiffstats
path: root/build
blob: 9b5d6f1bf60518640f95e653da64245d1ef5620f (plain) (tree)
1
2
3
4
5
6
7
8
9
                   
 
      
 
                                                                                        
                           
                                                             
                           
                                                         
                           
                                                     
                                
                                        
 



                    
              

 

                    

                                           
                 
                                                                                                                                         





           
      


                                    
                    




                                                   
                                                  
 
              
                                     
                                                    




                                              
                                                     
        
        
 





                                                                                      
                                 
 

                                                                                                 
              

      
                                                                








                                                                                    
        
 
      
 

                               
                    



                                           
 
                                             
                                                                

      


            
                                                                                               
                               


      






















                                                                                                                               
 
                 


                
                                                               
















                                                                                         

 
       
                                       
                                           
                                
                       
                                 
                                  
                                    
                            
                                        
                      
                                
                        
                        
                                 
                                 
                                        
                                            
                           
                    
                             
                                
                                    
                               
                     
                                      
                           
                                      
                           
                   
                                 
                   
                          
                          
                                                 
                        
                             
                               
                       
                                             
                                
                                   
                         
                        
                           
                              
                                                
                                         
                    
                         
                          
                      
                                    
                          
                                
                          
                         
                       
                     
                                
                                          
                                     
                                 
                      
                        
                  
                          

                                 
                             
                      
                        
                     
                          
                               
                        
                             
                             
                         
                             
                                              
                                 
                                           
                                            
                       
                          
                               
                    
                       
                         
                        
                         
                                       

                            
                                
                             
                                   
                               
                          
                       
                               
                                    
                                  
                                
                           
                     
                                      
                       
                        
                                       
                       
                             
                             
                    
                   
                         

                             
 
 
          
                      
         
 
                             

                                     
             

          
#!/usr/bin/env bash

set -E

DIRS="syntax indent compiler autoload ftplugin after/syntax after/indent after/ftplugin"
# shellcheck disable=SC2034
DIRS_BASIC="syntax compiler indent after/syntax after/indent"
# shellcheck disable=SC2034
DIRS_ALL="syntax indent compiler autoload ftplugin after"
# shellcheck disable=SC2034
DIRS_SYNTAX="syntax indent after/syntax after/indent"
DIRS_JAVASCRIPT="${DIRS} extras"
read -r -a DIRS_RM <<<"$DIRS_JAVASCRIPT"

OUTPUT=""

output() {
  OUTPUT="$OUTPUT$1"
  echo -n "$1"
}

download() {
  for pack in $1; do
    path="$(cut -d ':' -f 2 <<<"$pack")"
    dir="tmp/$(cut -d '/' -f 2 <<<"$path")"
    rm -rf "$dir"
    (mkdir -p "$dir" && curl --silent -L "https://codeload.github.com/$path/tar.gz/master" | tar -zx -C "$dir" --strip 1 && printf '.') &
  done

  wait
}

extract() {
  echo

  cat config.vim >> tmp/polyglot.vim

  for pack in $1; do
    name="$(cut -d ':' -f 1 <<<"$pack")"
    path="$(cut -d ':' -f 2 <<<"$pack")"
    dir="tmp/$(cut -d '/' -f 2 <<<"$path")"
    directories="DIRS$(cut -d ':' -f 3 <<<"$pack")"
    subtree="$(cut -d ':' -f 4 <<<"$pack")"
    output "- [$name](https://github.com/$path) ("

    subdirs=""
    for subdir in ${!directories}; do
      if [ -d "${dir}${subtree:-/}${subdir}" ]; then
        base="$(basename "$subdir")"
        if [[ "$subdirs" != *"$base"* ]]; then
          subdirs="$subdirs, $base"
        fi

        copy_dir "${dir}${subtree}" "$subdir" "$name"
      fi
    done

    # syntax for go.vim depends on autoload for go.vim, but we exclude the
    # autoload always and the ftplugin because it's too complex.  FML.
    if [ "${pack%%:*}" = "go" ]; then
      copy_file "${dir}${subtree}" "${dir}${subtree}/autoload/go/config.vim" "${name}"
    fi

    output "${subdirs##, })"$'\n'

    if (echo "julia coffee-script elixir fish git plantuml scala swift" | grep -qF "$name"); then
      echo "Skipping ftdetect installation of $name" >&2
      continue
    fi

    [ -d "${dir}/ftdetect" ] && for f in "${dir}/ftdetect/"*; do
      cat <<EOF >> tmp/polyglot.vim
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, '${pack%%:*}') == -1
  augroup filetypedetect
  " ${pack%%:*}, from ${f##*/ftdetect/} in ${pack#*:}
$(cat "${f}")
  augroup end
endif

EOF
    done

  done

  mv tmp/polyglot.vim ftdetect/

  for pack in $1; do
    name="$(cut -d ':' -f 1 <<<"$pack")"
    path="$(cut -d ':' -f 2 <<<"$pack")"
    dir="tmp/$(cut -d '/' -f 2 <<<"$path")"
    subtree="$(cut -d ':' -f 4 <<<"$pack")"

    if [ -d "$dir${subtree:-/}plugin" ]; then
      echo "Possible error (plugin directory exists): $path" >&2
    fi
  done
}

copy_dir() {
  find "$1/$2" \( -name '*.vim' -o -name '*.vital' \) -print0 | while read -r -d $'\0' file; do
    copy_file "$1" "$file" "$3"
  done
}

copy_file() {
  ## $1 is the build dir (e.g. tmp/vim-go)
  ## $2 is the full file path, as returned by `find` (e.g. tmp/vim-go/indent/go.vim)
  ## $3 is the name of the package (so that we can detect if it's disabled at runtime)
  local tmp_dir="$1"
  local file_in_tmp="$2"
  local file_basename="${2##*/}"
  local file_path="${file_in_tmp##$tmp_dir/}" # Just this file's (full) path
  file_path="${file_path%/*}"                # Minus the actual name of the file
  local file_in_dst="${file_path}/${file_basename}" # Could also be ${file_in_tmp##$tmp_dir/}
  local package_name="$3"

  if [ "${file_in_tmp##$tmp_dir/}" != "${file_in_dst}" ]; then
    echo "Failure in logic in build script; '${file_in_tmp##$tmp_dir/}' != '${file_in_dst}'.  Bailing." >&2
    exit 1
  fi

  mkdir -p "${file_path}"
  touch "$file_in_dst"

  # Use comma instead of / to handle cases like c/c++
  sed -e "s,%%PACK%%,${package_name}," -e "/%%CONTENT%%/{r ${file_in_tmp}" -e "d;}" plugin_guard.vim.template >> "$file_in_dst"
}

update_readme() {
  local tf of
  tf="$(mktemp)"
  of="$(mktemp)"
  LC_ALL=C sort <<<"$OUTPUT" | grep -vxE '[[:space:]]*' > "$of"

  awk 'suppress == 0 {
      gsub(/<!--Package Count-->[^<]*<!--\/Package Count-->/,
           "<!--Package Count-->'"$(awk 'END {print NR}' "$of")"'<!--/Package Count-->");
      print;
    }
    /<!--Language Packs-->/ {
      suppress = 1;
      while ( ( getline line < "'"$of"'" ) > 0 ) {
        print line;
      }
    }
    /<!--\/Language Packs-->/ {
      suppress = 0;
      print;
    }' "README.md" >"$tf"
  mv "$tf" "README.md"
}

PACKS="
  apiblueprint:sheerun/apiblueprint.vim
  applescript:mityu/vim-applescript:_SYNTAX
  asciidoc:asciidoc/vim-asciidoc
  yaml:stephpy/vim-yaml
  ansible:pearofducks/ansible-vim
  arduino:sudar/vim-arduino-syntax
  autohotkey:hnamikaw/vim-autohotkey
  blade:jwalton512/vim-blade
  c++11:octol/vim-cpp-enhanced-highlight
  c/c++:vim-jp/vim-cpp
  caddyfile:isobit/vim-caddyfile
  carp:hellerve/carp-vim
  cjsx:mtscout6/vim-cjsx
  clojure:guns/vim-clojure-static
  cmake:pboettch/vim-cmake-syntax
  coffee-script:kchmck/vim-coffee-script
  cryptol:victoredwardocallaghan/cryptol.vim
  crystal:rhysd/vim-crystal
  cql:elubow/cql-vim
  cucumber:tpope/vim-cucumber
  dart:dart-lang/dart-vim-plugin
  dockerfile:ekalinin/Dockerfile.vim
  elixir:elixir-lang/vim-elixir
  elm:ElmCast/elm-vim
  emberscript:yalesov/vim-ember-script
  emblem:yalesov/vim-emblem
  erlang:vim-erlang/vim-erlang-runtime
  ferm:vim-scripts/ferm.vim
  fish:dag/vim-fish
  fsharp:fsharp/vim-fsharp:_BASIC
  git:tpope/vim-git
  gmpl:maelvalais/gmpl.vim
  glsl:tikhomirov/vim-glsl
  gnuplot:vim-scripts/gnuplot-syntax-highlighting
  go:fatih/vim-go:_BASIC
  graphql:jparise/vim-graphql
  groovy:vim-scripts/groovy.vim
  haml:sheerun/vim-haml
  handlebars:mustache/vim-mustache-handlebars
  haproxy:CH-DanReif/haproxy.vim
  haskell:neovimhaskell/haskell-vim
  haxe:yaymukund/vim-haxe
  html5:othree/html5.vim
  i3:mboughaba/i3config.vim
  jasmine:glanotte/vim-jasmine
  javascript:pangloss/vim-javascript:_JAVASCRIPT
  jenkins:martinda/Jenkinsfile-vim-syntax
  json:elzr/vim-json
  json5:GutenYe/json5.vim
  jst:briancollins/vim-jst
  jsx:mxw/vim-jsx:_ALL
  julia:JuliaEditorSupport/julia-vim
  kotlin:udalov/kotlin-vim
  latex:LaTeX-Box-Team/LaTeX-Box
  less:groenewege/vim-less
  liquid:tpope/vim-liquid
  livescript:gkz/vim-ls
  lua:tbastos/vim-lua
  mako:sophacles/vim-bundle-mako
  markdown:plasticboy/vim-markdown:_SYNTAX
  mathematica:rsmenon/vim-mathematica
  moonscript:leafo/moonscript-vim
  nginx:chr4/nginx.vim
  nim:zah/nim.vim:_BASIC
  nix:LnL7/vim-nix
  objc:b4winckler/vim-objc
  ocaml:jrk/vim-ocaml
  octave:vim-scripts/octave.vim--
  opencl:petRUShka/vim-opencl
  org:jceb/vim-orgmode
  perl:vim-perl/vim-perl
  pgsql:exu/pgsql.vim
  php:StanAngeloff/php.vim
  plantuml:aklt/plantuml-syntax
  pony:jakwings/vim-pony
  powershell:PProvost/vim-ps1
  protobuf:uarun/vim-protobuf
  pug:digitaltoad/vim-pug
  puppet:voxpupuli/vim-puppet
  purescript:purescript-contrib/purescript-vim
  python:vim-python/python-syntax
  python-compiler:aliev/vim-compiler-python
  python-ident:Vimjas/vim-python-pep8-indent
  qml:peterhoeg/vim-qml
  r-lang:vim-scripts/R.vim
  racket:wlangstroth/vim-racket
  raml:IN3D/vim-raml
  ragel:jneen/ragel.vim
  rspec:sheerun/rspec.vim
  ruby:vim-ruby/vim-ruby
  rust:rust-lang/rust.vim
  rst:marshallward/vim-restructuredtext
  sbt:derekwyatt/vim-sbt
  scala:derekwyatt/vim-scala
  scss:cakebaker/scss-syntax.vim
  slim:slim-template/vim-slim
  slime:slime-lang/vim-slime-syntax
  solidity:tomlion/vim-solidity
  stylus:wavded/vim-stylus
  swift:keith/swift.vim
  sxhkd:baskerville/vim-sxhkdrc
  systemd:wgwoods/vim-systemd-syntax
  terraform:hashivim/vim-terraform
  textile:timcharper/textile.vim
  thrift:solarnz/thrift.vim
  tmux:keith/tmux.vim
  tomdoc:wellbredgrapefruit/tomdoc.vim
  toml:cespare/vim-toml
  twig:lumiliet/vim-twig
  typescript:leafgarland/typescript-vim
  vala:arrufat/vala.vim
  vbnet:vim-scripts/vbnet.vim
  vcl:smerrill/vcl-vim-plugin
  vifm:vifm/vifm.vim
  vue:posva/vim-vue
  vm:lepture/vim-velocity
  xls:vim-scripts/XSLT-syntax
  yard:sheerun/vim-yardoc
"

rm -rf tmp
rm -rf "${DIRS_RM[@]}"
mkdir tmp

printf "Downloading packs..."
download "$(sed '/^#/d' <<<"$PACKS")"
extract "$(sed '/^#/d' <<<"$PACKS")"
update_readme

rm -rf tmp