Skip to content

Commit bef2035

Browse files
committed
go: add zstyle to prevent listing packages from GOROOT and GOPATH
Adding all of GOROOT means all of stdlib is added as completions to many commands, which I find rather noisy and rarely useful. Before: [~/check]% go install <Tab> archive/ context/ fmt/ log/ regexp/ testing/ bufio/ crypto/ go/ math/ runtime/ text/ builtin/ database/ hash/ mime/ sort/ time/ bytes/ debug/ html/ net/ strconv/ unicode/ check.go encoding/ image/ os/ strings/ unsafe/ cmd/ errors/ index/ path/ sync/ vendor/ compress/ expvar/ internal/ plugin/ syscall/ container/ flag/ io/ reflect/ testdata/ After: [~/check]% go install <Tab> # completes to ./check.go, which is the only file in this small package. Also add a setting to disable GOPATH, as it's kind deprecated and on its way out. Sometimes I have some stuff "go get"'d in there, but I rarely want that as completions.
1 parent 3b247d3 commit bef2035

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/_golang

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343
# * Go authors
4444
#
4545
# ------------------------------------------------------------------------------
46+
# Notes
47+
# -----
48+
#
49+
# * To disable listing packages from GOROOT (i.e. Go stdlib) in completions use:
50+
#
51+
# zstyle ':completion:*:go:*' no-goroot true
52+
#
53+
# * To disable listing packages from GOPATH in completions use:
54+
#
55+
# zstyle ':completion:*:go:*' no-gopath true
56+
#
57+
# ------------------------------------------------------------------------------
4658

4759
__go_buildmodes() {
4860
local -a buildmodes
@@ -358,11 +370,16 @@ case $state in
358370
__go_packages() {
359371
local gopaths
360372
declare -a gopaths
361-
gopaths=("${(s/:/)$(go env GOPATH)}")
362-
gopaths+=("$(go env GOROOT)")
373+
if ! zstyle -t ":completion:${curcontext}:" no-gopath; then
374+
gopaths=("${(s/:/)$(go env GOPATH)}")
375+
fi
376+
if ! zstyle -t ":completion:${curcontext}:" no-goroot; then
377+
gopaths+=("$(go env GOROOT)")
378+
fi
363379
for p in $gopaths; do
364380
_path_files $@ -W "$p/src" -/
365381
done
382+
366383
# no special treatment for
367384
# - relative paths starting with ..
368385
# - absolute path starting with /

0 commit comments

Comments
 (0)