fd50759e39a8b0e27f56f1e56a8240de541d8271

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #1254 from systemfreund/master

Added completion plugin for "Go" compiler 

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/go/go.plugin.zsh b/plugins/go/go.plugin.zsh
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..23afa96569e18d426125cd48921786e59a1faa2c
  4--- /dev/null
  5+++ b/plugins/go/go.plugin.zsh
  6@@ -0,0 +1,151 @@
  7+# install in /etc/zsh/zshrc or your personal .zshrc
  8+
  9+# gc
 10+prefixes=(5 6 8)
 11+for p in $prefixes; do
 12+	compctl -g "*.${p}" ${p}l
 13+	compctl -g "*.go" ${p}g
 14+done
 15+
 16+# standard go tools
 17+compctl -g "*.go" gofmt
 18+
 19+# gccgo
 20+compctl -g "*.go" gccgo
 21+
 22+# go tool
 23+__go_tool_complete() {
 24+  typeset -a commands build_flags
 25+  commands+=(
 26+    'build[compile packages and dependencies]'
 27+    'clean[remove object files]'
 28+    'doc[run godoc on package sources]'
 29+    'fix[run go tool fix on packages]'
 30+    'fmt[run gofmt on package sources]'
 31+    'get[download and install packages and dependencies]'
 32+    'help[display help]'
 33+    'install[compile and install packages and dependencies]'
 34+    'list[list packages]'
 35+    'run[compile and run Go program]'
 36+    'test[test packages]'
 37+    'tool[run specified go tool]'
 38+    'version[print Go version]'
 39+    'vet[run go tool vet on packages]'
 40+  )
 41+  if (( CURRENT == 2 )); then
 42+    # explain go commands
 43+    _values 'go tool commands' ${commands[@]}
 44+    return
 45+  fi
 46+  build_flags=(
 47+    '-a[force reinstallation of packages that are already up-to-date]'
 48+    '-n[print the commands but do not run them]'
 49+    "-p[number of parallel builds]:number"
 50+    '-x[print the commands]'
 51+    "-work[print temporary directory name and keep it]"
 52+    "-gcflags[flags for 5g/6g/8g]:flags"
 53+    "-ldflags[flags for 5l/6l/8l]:flags"
 54+    "-gccgoflags[flags for gccgo]:flags"
 55+  )
 56+  __go_list() {
 57+      local expl importpaths
 58+      declare -a importpaths
 59+      importpaths=($(go list ${words[$CURRENT]}... 2>/dev/null))
 60+      _wanted importpaths expl 'import paths' compadd "$@" - "${importpaths[@]}"
 61+  }
 62+  case ${words[2]} in
 63+  clean|doc)
 64+      _arguments -s -w : '*:importpaths:__go_list'
 65+      ;;
 66+  fix|fmt|list|vet)
 67+      _alternative ':importpaths:__go_list' ':files:_path_files -g "*.go"'
 68+      ;;
 69+  install)
 70+      _arguments -s -w : ${build_flags[@]} \
 71+        "-v[show package names]" \
 72+	'*:importpaths:__go_list'
 73+      ;;
 74+  get)
 75+      _arguments -s -w : \
 76+        ${build_flags[@]}
 77+      ;;
 78+  build)
 79+      _arguments -s -w : \
 80+        ${build_flags[@]} \
 81+        "-v[show package names]" \
 82+        "-o[output file]:file:_files" \
 83+        "*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \"*.go\"' }"
 84+      ;;
 85+  test)
 86+      _arguments -s -w : \
 87+        ${build_flags[@]} \
 88+        "-c[do not run, compile the test binary]" \
 89+        "-i[do not run, install dependencies]" \
 90+        "-v[print test output]" \
 91+        "-x[print the commands]" \
 92+        "-short[use short mode]" \
 93+        "-parallel[number of parallel tests]:number" \
 94+        "-cpu[values of GOMAXPROCS to use]:number list" \
 95+        "-run[run tests and examples matching regexp]:regexp" \
 96+        "-bench[run benchmarks matching regexp]:regexp" \
 97+        "-benchtime[run each benchmark during n seconds]:duration" \
 98+        "-timeout[kill test after that duration]:duration" \
 99+        "-cpuprofile[write CPU profile to file]:file:_files" \
100+        "-memprofile[write heap profile to file]:file:_files" \
101+        "-memprofilerate[set heap profiling rate]:number" \
102+        "*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \"*.go\"' }"
103+      ;;
104+  help)
105+      _values "${commands[@]}" \