Update environment variable completion

And don't use global variables
This commit is contained in:
Shohei YOSHIDA 2024-07-31 16:42:02 +09:00
parent f036321bc4
commit 22222832d8
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 41 additions and 72 deletions

View File

@ -207,114 +207,84 @@ __go_envvarvals() {
# decide which variable to go to. if $1 is not set, then __go_envvarvals is # decide which variable to go to. if $1 is not set, then __go_envvarvals is
# called from the `go env` completion and the current word (with all after # called from the `go env` completion and the current word (with all after
# the first '=' removed) is the current variable. # the first '=' removed) is the current variable.
local variable local env_variable=${1-${words[$CURRENT]%%=*}}
variable=${1-${words[$CURRENT]%%=*}} case $env_variable in
case $variable in (GO111MODULE)
_values "module mode" off on auto
;;
# commands # commands
AR) (AR|CC|CXX|FC|GCCGO)
;&
CC)
;&
CXX)
;&
FC)
;&
GCCGO)
_command_names -e _command_names -e
;; ;;
# directories (using fallthrough) # directories
GOBIN) (GOBIN|GOCACHE|GOTMPDIR|GOTOOLDIR|GOROOT|GOROOT_FINAL|GCCGOTOOLDIR|GOPATH|GOMODCACHE|GOCOVERDIR)
;&
GOCACHE)
;&
GOTMPDIR)
;&
GOTOOLDIR)
;&
GOROOT)
;&
GOROOT_FINAL)
;&
GCCGOTOOLDIR)
;&
GOPATH)
;&
GOMODCACHE)
_files -/ _files -/
;; ;;
# regular files (using fallthrough) # regular files
GOMOD) (GOMOD|PKG_CONFIG|GOENV)
;&
PKG_CONFIG)
;&
GOENV)
_files _files
;; ;;
# special # special
GOHOSTOS) (GOHOSTOS|GOOS)
;&
GOOS)
# from https://golang.org/doc/install/source#environment # from https://golang.org/doc/install/source#environment
_values 'operating system' aix android darwin dragonfly freebsd illumos ios js linux netbsd openbsd plan9 solaris windows wasip1 local -a supported_os=(
aix android darwin dragonfly freebsd illumos ios js linux netbsd openbsd plan9 solaris wasip1 windows
)
_values 'operating system' $supported_os
;; ;;
GOHOSTARCH) (GOHOSTARCH|GOARCH)
;& local -a supported_arch=(
GOARCH) amd64 386 arm arm64 ppc64le ppc64 mips64le mips64 mipsle mips s390x riscv64 wasm
_values 'architecture' amd64 386 arm64 arm ppc64 ppc64le mips mipsle mips64 mips64le riscv64 s390x wasm )
_values 'architecture' $supported_arch
;; ;;
CGO_ENABLED) (CGO_ENABLED)
_values 'enable/disable cgo' 0 1 _values 'enable/disable cgo' 0 1
;; ;;
GO_EXTLINK_ENABLED) (GO_EXTLINK_ENABLED)
_values 'enable/disable external linkage' 0 1 _values 'enable/disable external linkage' 0 1
;; ;;
GOARM) (GOARM)
_values 'target arm architecture' 5 6 7 _values 'target arm architecture' 5 6 7
;; ;;
GO386) (GO386)
_values 'x86 floating point instruction set' 387 sse2 _values 'x86 floating point instruction set' sse2 softfloat
;; ;;
GOAMD64) (GOAMD64)
_values 'amd64 instruction set' v1 v2 v3 v4 _values 'amd64 instruction set' v1 v2 v3 v4
;; ;;
GOMIPS*) (GOMIPS*)
_values 'mips floating point instructions' hardfloat softfloat _values 'mips floating point instructions' hardfloat softfloat
;; ;;
GOPPC64) (GOPPC64)
_values 'powerpc64 instruction set' power8 power9 power10 _values 'powerpc64 instruction set' power8 power9 power10
;; ;;
GOWASM) (GOWASM)
_values 'web assembly features' -s ',' satconv signext _values 'web assembly features' -s ',' satconv signext
;; ;;
GOPROXY) (GOPROXY)
_urls _urls
;; ;;
GOEXE) (GOEXE)
_message "suffix for executables" _message "suffix for executables"
;; ;;
CGO_*FLAGS_*ALLOW) (CGO_*FLAGS_*ALLOW)
_message "regexp" _message "regexp"
;; ;;
CGO_*FLAGS) (CGO_*FLAGS)
_dispatch $service -value-,${variable#CGO_},-default- _dispatch $service -value-,${variable#CGO_},-default-
;; ;;
GODEBUG) (GODEBUG)
__go_runtimedebug __go_runtimedebug
;; ;;
GOFLAGS) (GOFLAGS)
# not implemented, sorry # not implemented, sorry
;; ;;
GOINSECURE) (GOINSECURE|GOPRIVATE|GONOPROXY|GONOSUMDB)
;&
GOPRIVATE)
;&
GONOPROXY)
;&
GONOSUMDB)
# comma separated glob patterns (in the syntax of Go's path.Match) # comma separated glob patterns (in the syntax of Go's path.Match)
_message "comma separated glob pattern" _message "comma separated glob pattern"
;; ;;
GOSUMDB) (GOSUMDB)
_message "e.g. sum.golang.org+<publickey> https://sum.golang.org" _message "e.g. sum.golang.org+<publickey> https://sum.golang.org"
;; ;;
esac esac
@ -355,14 +325,13 @@ __go_fix_names() {
} }
if [[ "$service" = -value-* ]]; then if [[ "$service" = -value-* ]]; then
variable=${${service%,-default-}#-value-,} local env_variable=${${service%,-default-}#-value-,}
# some special variables are not read from the environment # some special variables are not read from the environment
local -a blacklist local -a blacklist=('GOEXE' 'GOGCCFLAGS' 'GOHOSTARCH' 'GOHOSTOS' 'GOMOD' 'GOTOOLDIR')
blacklist=('GOEXE' 'GOGCCFLAGS' 'GOHOSTARCH' 'GOHOSTOS' 'GOMOD' 'GOTOOLDIR') if (($blacklist[(I)$env_variable])); then
if (($blacklist[(I)$variable])); then
return return
fi fi
__go_envvarvals $variable __go_envvarvals $env_variable
return return
fi fi