| OLD | NEW |
| (Empty) |
| 1 # install in /etc/zsh/zshrc or your personal .zshrc | |
| 2 | |
| 3 # gc | |
| 4 prefixes=(5 6 8) | |
| 5 for p in $prefixes; do | |
| 6 compctl -g "*.${p}" ${p}l | |
| 7 compctl -g "*.go" ${p}g | |
| 8 done | |
| 9 | |
| 10 # standard go tools | |
| 11 compctl -g "*.go" gofmt | |
| 12 | |
| 13 # gccgo | |
| 14 compctl -g "*.go" gccgo | |
| 15 | |
| 16 # go tool | |
| 17 __go_tool_complete() { | |
| 18 typeset -a commands build_flags | |
| 19 commands+=( | |
| 20 'build[compile packages and dependencies]' | |
| 21 'clean[remove object files]' | |
| 22 'env[print Go environment information]' | |
| 23 'fix[run go tool fix on packages]' | |
| 24 'fmt[run gofmt on package sources]' | |
| 25 'get[download and install packages and dependencies]' | |
| 26 'help[display help]' | |
| 27 'install[compile and install packages and dependencies]' | |
| 28 'list[list packages]' | |
| 29 'run[compile and run Go program]' | |
| 30 'test[test packages]' | |
| 31 'tool[run specified go tool]' | |
| 32 'version[print Go version]' | |
| 33 'vet[run go tool vet on packages]' | |
| 34 ) | |
| 35 if (( CURRENT == 2 )); then | |
| 36 # explain go commands | |
| 37 _values 'go tool commands' ${commands[@]} | |
| 38 return | |
| 39 fi | |
| 40 build_flags=( | |
| 41 '-a[force reinstallation of packages that are already up-to-date]' | |
| 42 '-n[print the commands but do not run them]' | |
| 43 '-p[number of parallel builds]:number' | |
| 44 '-race[enable data race detection]' | |
| 45 '-x[print the commands]' | |
| 46 '-work[print temporary directory name and keep it]' | |
| 47 '-ccflags[flags for 5c/6c/8c]:flags' | |
| 48 '-gcflags[flags for 5g/6g/8g]:flags' | |
| 49 '-ldflags[flags for 5l/6l/8l]:flags' | |
| 50 '-gccgoflags[flags for gccgo]:flags' | |
| 51 '-compiler[name of compiler to use]:name' | |
| 52 '-installsuffix[suffix to add to package directory]:suffix' | |
| 53 '-tags[list of build tags to consider satisfied]:tags' | |
| 54 ) | |
| 55 __go_list() { | |
| 56 local expl importpaths | |
| 57 declare -a importpaths | |
| 58 importpaths=($(go list ${words[$CURRENT]}... 2>/dev/null)) | |
| 59 _wanted importpaths expl 'import paths' compadd "$@" - "${importpaths[@]}" | |
| 60 } | |
| 61 case ${words[2]} in | |
| 62 clean|doc) | |
| 63 _arguments -s -w : '*:importpaths:__go_list' | |
| 64 ;; | |
| 65 fix|fmt|list|vet) | |
| 66 _alternative ':importpaths:__go_list' ':files:_path_files -g "*.go"' | |
| 67 ;; | |
| 68 install) | |
| 69 _arguments -s -w : ${build_flags[@]} \ | |
| 70 "-v[show package names]" \ | |
| 71 '*:importpaths:__go_list' | |
| 72 ;; | |
| 73 get) | |
| 74 _arguments -s -w : \ | |
| 75 ${build_flags[@]} | |
| 76 ;; | |
| 77 build) | |
| 78 _arguments -s -w : \ | |
| 79 ${build_flags[@]} \ | |
| 80 "-v[show package names]" \ | |
| 81 "-o[output file]:file:_files" \ | |
| 82 "*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \ "*.go\"' }" | |
| 83 ;; | |
| 84 test) | |
| 85 _arguments -s -w : \ | |
| 86 ${build_flags[@]} \ | |
| 87 "-c[do not run, compile the test binary]" \ | |
| 88 "-i[do not run, install dependencies]" \ | |
| 89 "-v[print test output]" \ | |
| 90 "-x[print the commands]" \ | |
| 91 "-short[use short mode]" \ | |
| 92 "-parallel[number of parallel tests]:number" \ | |
| 93 "-cpu[values of GOMAXPROCS to use]:number list" \ | |
| 94 "-cover[enable coverage analysis]" \ | |
| 95 "-run[run tests and examples matching regexp]:regexp" \ | |
| 96 "-bench[run benchmarks matching regexp]:regexp" \ | |
| 97 "-benchmem[print memory allocation stats]" \ | |
| 98 "-benchtime[run each benchmark until taking this long]:duration" \ | |
| 99 "-blockprofile[write goroutine blocking profile to file]:file" \ | |
| 100 "-blockprofilerate[set sampling rate of goroutine blocking profile]:numb er" \ | |
| 101 "-timeout[kill test after that duration]:duration" \ | |
| 102 "-cpuprofile[write CPU profile to file]:file:_files" \ | |
| 103 "-memprofile[write heap profile to file]:file:_files" \ | |
| 104 "-memprofilerate[set heap profiling rate]:number" \ | |
| 105 "*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \ "*.go\"' }" | |
| 106 ;; | |
| 107 help) | |
| 108 _values "${commands[@]}" \ | |
| 109 'c[how to call C code]' \ | |
| 110 'importpath[description of import path]' \ | |
| 111 'gopath[GOPATH environment variable]' \ | |
| 112 'packages[description of package lists]' \ | |
| 113 'testflag[description of testing flags]' \ | |
| 114 'testfunc[description of testing functions]' | |
| 115 ;; | |
| 116 run) | |
| 117 _arguments -s -w : \ | |
| 118 ${build_flags[@]} \ | |
| 119 '*:file:_path_files -g "*.go"' | |
| 120 ;; | |
| 121 tool) | |
| 122 if (( CURRENT == 3 )); then | |
| 123 _values "go tool" $(go tool) | |
| 124 return | |
| 125 fi | |
| 126 case ${words[3]} in | |
| 127 [568]g) | |
| 128 _arguments -s -w : \ | |
| 129 '-I[search for packages in DIR]:includes:_path_files -/' \ | |
| 130 '-L[show full path in file:line prints]' \ | |
| 131 '-S[print the assembly language]' \ | |
| 132 '-V[print the compiler version]' \ | |
| 133 '-e[no limit on number of errors printed]' \ | |
| 134 '-h[panic on an error]' \ | |
| 135 '-l[disable inlining]' \ | |
| 136 '-m[print optimization decisions]' \ | |
| 137 '-o[file specify output file]:file' \ | |
| 138 '-p[assumed import path for this code]:importpath' \ | |
| 139 '-u[disable package unsafe]' \ | |
| 140 "*:file:_files -g '*.go'" | |
| 141 ;; | |
| 142 [568]l) | |
| 143 local O=${words[3]%l} | |
| 144 _arguments -s -w : \ | |
| 145 '-o[file specify output file]:file' \ | |
| 146 '-L[search for packages in DIR]:includes:_path_files -/' \ | |
| 147 "*:file:_files -g '*.[ao$O]'" | |
| 148 ;; | |
| 149 dist) | |
| 150 _values "dist tool" banner bootstrap clean env install version | |
| 151 ;; | |
| 152 *) | |
| 153 # use files by default | |
| 154 _files | |
| 155 ;; | |
| 156 esac | |
| 157 ;; | |
| 158 esac | |
| 159 } | |
| 160 | |
| 161 compdef __go_tool_complete go | |
| OLD | NEW |