From e73235f0dfb9e483d019ede7abd019f29434ab89 Mon Sep 17 00:00:00 2001 From: Paul Seyfert Date: Thu, 18 Jul 2019 23:07:32 +0200 Subject: [PATCH] [golang] unify package completion for build and run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * let both `go build` and `go run` suggest local files and dirs with `go build ./something` * let both suggest package identifiers `go build github.com/username/reponame` * automatically prefix relative paths with './' `go build file` → `go build ./file.go` --- src/_golang | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/_golang b/src/_golang index 5515529..8d84caa 100644 --- a/src/_golang +++ b/src/_golang @@ -117,8 +117,18 @@ case $state in gopaths=("${(s/:/)$(go env GOPATH)}") gopaths+=("$(go env GOROOT)") for p in $gopaths; do - _path_files -W "$p/src" -/ + _path_files $@ -W "$p/src" -/ done + # no special treatment for + # - relative paths starting with .. + # - absolute path starting with / + # - variables, substitutions, subshells + if [[ $words[$CURRENT] = ..* || $words[$CURRENT] = \$* || $words[$CURRENT] = /* ]]; then + _path_files $@ -/ -g '*.go' + else + # go build accepts paths relative to the cwd but they must start with './', so prefix them + _path_files $@ -P './' -/ -g '*.go' + fi } case $words[1] in @@ -266,7 +276,7 @@ case $state in _arguments \ ${build_flags[@]} \ '-exec[invoke the binary using xprog]:xporg' \ - '*:file:_files -g "*.go(-.)"' + '*:importpaths:__go_packages' ;; test)