From bef2035b69f81948eeea1836e640d6053e91299a Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 3 Jun 2020 14:54:26 +0800 Subject: [PATCH] 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 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 # 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. --- src/_golang | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/_golang b/src/_golang index ed25db8..5b0c8b7 100644 --- a/src/_golang +++ b/src/_golang @@ -43,6 +43,18 @@ # * Go authors # # ------------------------------------------------------------------------------ +# Notes +# ----- +# +# * To disable listing packages from GOROOT (i.e. Go stdlib) in completions use: +# +# zstyle ':completion:*:go:*' no-goroot true +# +# * To disable listing packages from GOPATH in completions use: +# +# zstyle ':completion:*:go:*' no-gopath true +# +# ------------------------------------------------------------------------------ __go_buildmodes() { local -a buildmodes @@ -358,11 +370,16 @@ case $state in __go_packages() { local gopaths declare -a gopaths - gopaths=("${(s/:/)$(go env GOPATH)}") - gopaths+=("$(go env GOROOT)") + if ! zstyle -t ":completion:${curcontext}:" no-gopath; then + gopaths=("${(s/:/)$(go env GOPATH)}") + fi + if ! zstyle -t ":completion:${curcontext}:" no-goroot; then + gopaths+=("$(go env GOROOT)") + fi for p in $gopaths; do _path_files $@ -W "$p/src" -/ done + # no special treatment for # - relative paths starting with .. # - absolute path starting with /