Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go: add zstyle to prevent listing packages from GOROOT and GOPATH #750

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/_golang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 /
Expand Down