github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/misc/zsh/go (about)

     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      'doc[run godoc on package sources]'
    23      'env[print Go environment information]'
    24      'fix[run go tool fix on packages]'
    25      'fmt[run gofmt on package sources]'
    26      'get[download and install packages and dependencies]'
    27      'help[display help]'
    28      'install[compile and install packages and dependencies]'
    29      'list[list packages]'
    30      'run[compile and run Go program]'
    31      'test[test packages]'
    32      'tool[run specified go tool]'
    33      'version[print Go version]'
    34      'vet[run go tool vet on packages]'
    35    )
    36    if (( CURRENT == 2 )); then
    37      # explain go commands
    38      _values 'go tool commands' ${commands[@]}
    39      return
    40    fi
    41    build_flags=(
    42      '-a[force reinstallation of packages that are already up-to-date]'
    43      '-n[print the commands but do not run them]'
    44      '-p[number of parallel builds]:number'
    45      '-race[enable data race detection]'
    46      '-x[print the commands]'
    47      '-work[print temporary directory name and keep it]'
    48      '-ccflags[flags for 5c/6c/8c]:flags'
    49      '-gcflags[flags for 5g/6g/8g]:flags'
    50      '-ldflags[flags for 5l/6l/8l]:flags'
    51      '-gccgoflags[flags for gccgo]:flags'
    52      '-compiler[name of compiler to use]:name'
    53      '-installsuffix[suffix to add to package directory]:suffix'
    54      '-tags[list of build tags to consider satisfied]:tags'
    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          "-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]:number" \
   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          'gopath[GOPATH environment variable]' \
   110          'packages[description of package lists]' \
   111          'remote[remote import path syntax]' \
   112          'testflag[description of testing flags]' \
   113          'testfunc[description of testing functions]'
   114        ;;
   115    run)
   116        _arguments -s -w : \
   117            ${build_flags[@]} \
   118            '*:file:_path_files -g "*.go"'
   119        ;;
   120    tool)
   121        if (( CURRENT == 3 )); then
   122            _values "go tool" $(go tool)
   123            return
   124        fi
   125        case ${words[3]} in
   126        [568]g)
   127            _arguments -s -w : \
   128                '-I[search for packages in DIR]:includes:_path_files -/' \
   129                '-L[show full path in file:line prints]' \
   130                '-S[print the assembly language]' \
   131                '-V[print the compiler version]' \
   132                '-e[no limit on number of errors printed]' \
   133                '-h[panic on an error]' \
   134                '-l[disable inlining]' \
   135                '-m[print optimization decisions]' \
   136                '-o[file specify output file]:file' \
   137                '-p[assumed import path for this code]:importpath' \
   138                '-u[disable package unsafe]' \
   139                "*:file:_files -g '*.go'"
   140            ;;
   141        [568]l)
   142            local O=${words[3]%l}
   143            _arguments -s -w : \
   144                '-o[file specify output file]:file' \
   145                '-L[search for packages in DIR]:includes:_path_files -/' \
   146                "*:file:_files -g '*.[ao$O]'"
   147            ;;
   148        dist)
   149            _values "dist tool" banner bootstrap clean env install version
   150            ;;
   151        *)
   152            # use files by default
   153            _files
   154            ;;
   155        esac
   156        ;;
   157    esac
   158  }
   159  
   160  compdef __go_tool_complete go