Use __golang prefix instead of __go prefix

Because __go_ is used in zsh old golang completions and they could
conflict with functions in _golang.
This commit is contained in:
Shohei YOSHIDA 2026-03-26 14:04:23 +09:00
parent b1ffb771c9
commit 748d11083a
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 38 additions and 38 deletions

View File

@ -44,7 +44,7 @@
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
__go_buildmodes() { __golang_buildmodes() {
local -a buildmodes=( local -a buildmodes=(
'archive[non-main packages into .a files]' 'archive[non-main packages into .a files]'
'c-archive[main package, plus all packages it imports, into a C archive file]' 'c-archive[main package, plus all packages it imports, into a C archive file]'
@ -59,7 +59,7 @@ __go_buildmodes() {
_values 'mode' $buildmodes _values 'mode' $buildmodes
} }
__go_runtimedebug() { __golang_runtimedebug() {
local -a vars=( local -a vars=(
'allocfreetrace[profile allocations]:boolean:(1 0)' 'allocfreetrace[profile allocations]:boolean:(1 0)'
'clobberfree[clobber memory after free]:boolean:(1 0)' 'clobberfree[clobber memory after free]:boolean:(1 0)'
@ -84,7 +84,7 @@ __go_runtimedebug() {
_values -s ',' -S '=' "runtime debug behavior" $vars[@] _values -s ',' -S '=' "runtime debug behavior" $vars[@]
} }
__go_gcdebugflags() { __golang_gcdebugflags() {
_values -s , -S = 'debug flag' \ _values -s , -S = 'debug flag' \
'append[print information about append compilation]' \ 'append[print information about append compilation]' \
'checkptr[instrument unsafe pointer conversions]:pointer conversion checks:((0\:"instrumentation disabled" 1\:"conversions involving unsafe.Pointer are instrumented" 2\:"conversions to unsafe.Pointer force heap allocation"))' \ 'checkptr[instrument unsafe pointer conversions]:pointer conversion checks:((0\:"instrumentation disabled" 1\:"conversions involving unsafe.Pointer are instrumented" 2\:"conversions to unsafe.Pointer force heap allocation"))' \
@ -109,7 +109,7 @@ __go_gcdebugflags() {
'ssa/help[print help about SSA debugging]' 'ssa/help[print help about SSA debugging]'
} }
__go_gcflags() { __golang_gcflags() {
_arguments \ _arguments \
'-%[debug non-static initializers]' \ '-%[debug non-static initializers]' \
'-c=[concurrency during compilation]:int' \ '-c=[concurrency during compilation]:int' \
@ -131,7 +131,7 @@ __go_gcflags() {
'-buildid=[record id as the build id in the export metadata]:id' \ '-buildid=[record id as the build id in the export metadata]:id' \
'-complete[compiling complete package (no C or assembly)]' \ '-complete[compiling complete package (no C or assembly)]' \
'-cpuprofile=[write cpu profile to file]:file' \ '-cpuprofile=[write cpu profile to file]:file' \
'-d=[print debug information about items in list; try -d help]:list: __go_gcdebugflags' \ '-d=[print debug information about items in list; try -d help]:list: __golang_gcdebugflags' \
'-dwarf[generate DWARF symbols (default true)]' \ '-dwarf[generate DWARF symbols (default true)]' \
'-dwarfbasentries[use base address selection entries in DWARF (default true)]' \ '-dwarfbasentries[use base address selection entries in DWARF (default true)]' \
'-dwarflocationlists[add location lists to DWARF in optimized mode (default true)]' \ '-dwarflocationlists[add location lists to DWARF in optimized mode (default true)]' \
@ -173,7 +173,7 @@ __go_gcflags() {
'-wb[enable write barrier (default true)]' '-wb[enable write barrier (default true)]'
} }
__go_pgo() { __golang_pgo() {
_alternative \ _alternative \
"name:name:(auto off)" \ "name:name:(auto off)" \
"file:file:_files" "file:file:_files"
@ -203,9 +203,9 @@ local -a commands=(
'help:get more information about a command' 'help:get more information about a command'
) )
__go_envvarvals() { __golang_envvarvals() {
# if __go_envvarvals is called for -value-, I use the function argument to # if __golang_envvarvals is called for -value-, I use the function argument to
# 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 __golang_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 env_variable=${1-${words[$CURRENT]%%=*}} local env_variable=${1-${words[$CURRENT]%%=*}}
@ -276,7 +276,7 @@ __go_envvarvals() {
_dispatch $service -value-,${variable#CGO_},-default- _dispatch $service -value-,${variable#CGO_},-default-
;; ;;
(GODEBUG) (GODEBUG)
__go_runtimedebug __golang_runtimedebug
;; ;;
(GOFLAGS) (GOFLAGS)
# not implemented, sorry # not implemented, sorry
@ -294,7 +294,7 @@ __go_envvarvals() {
esac esac
} }
__go_packages() { __golang_packages() {
local -a gopaths=("${(s/:/)$(go env GOPATH)}") local -a gopaths=("${(s/:/)$(go env GOPATH)}")
gopaths+=("$(go env GOROOT)") gopaths+=("$(go env GOROOT)")
for p in $gopaths; do for p in $gopaths; do
@ -312,7 +312,7 @@ __go_packages() {
fi fi
} }
__go_fix_analyzers() { __golang_fix_analyzers() {
local -a fix_analyzers=( local -a fix_analyzers=(
"any[replace interface{} with any]" "any[replace interface{} with any]"
"buildtag[check //go:build and // +build directives]" "buildtag[check //go:build and // +build directives]"
@ -341,7 +341,7 @@ __go_fix_analyzers() {
_values 'analyzer' $fix_analyzers _values 'analyzer' $fix_analyzers
} }
__go_pprof_symbolize_types() { __golang_pprof_symbolize_types() {
local -a symbolize_types=( local -a symbolize_types=(
"none[Do not attempt symbolization]" "none[Do not attempt symbolization]"
"local[Examine only local binaries]" "local[Examine only local binaries]"
@ -360,7 +360,7 @@ if [[ "$service" = -value-* ]]; then
if (($blacklist[(I)$env_variable])); then if (($blacklist[(I)$env_variable])); then
return return
fi fi
__go_envvarvals $env_variable __golang_envvarvals $env_variable
return return
fi fi
@ -382,16 +382,16 @@ case $state in
'-work[print temporary work directory and keep it]' '-work[print temporary work directory and keep it]'
'-x[print the commands]' '-x[print the commands]'
'-asmflags[arguments for each go tool asm invocation]:flags' '-asmflags[arguments for each go tool asm invocation]:flags'
'-buildmode[build mode to use]:mode:__go_buildmodes' '-buildmode[build mode to use]:mode:__golang_buildmodes'
'-buildvcs[stamp binaries with version control information]:mode:(internal external auto)' '-buildvcs[stamp binaries with version control information]:mode:(internal external auto)'
'-compiler[name of compiler to use]:name' '-compiler[name of compiler to use]:name'
'-gccgoflags[arguments for gccgo]:args' '-gccgoflags[arguments for gccgo]:args'
'*-gcflags=[arguments for each go tool compile invocation]:args:__go_gcflags' '*-gcflags=[arguments for each go tool compile invocation]:args:__golang_gcflags'
'-installsuffix[suffix to add to package directory]:suffix' '-installsuffix[suffix to add to package directory]:suffix'
'-ldflags[arguments to pass on each go tool link invocation.]:flags' '-ldflags[arguments to pass on each go tool link invocation.]:flags'
'-linkshared[link against shared libraries]' '-linkshared[link against shared libraries]'
'-overlay[read a JSON config file that provides an overlay for build operations]:file:_files -g "*.json"' '-overlay[read a JSON config file that provides an overlay for build operations]:file:_files -g "*.json"'
'-pgo[specify the file path of a profile for profile-guided optimization]:file_or_profile:__go_pgo' '-pgo[specify the file path of a profile for profile-guided optimization]:file_or_profile:__golang_pgo'
'-pkgdir[install and load all packages from dir]:dir' '-pkgdir[install and load all packages from dir]:dir'
'-tags[list of build tags to consider satisfied]:tags' '-tags[list of build tags to consider satisfied]:tags'
'-trimpath[remove all file system paths from the resulting executable]' '-trimpath[remove all file system paths from the resulting executable]'
@ -425,7 +425,7 @@ case $state in
'help:get more information about a command' 'help:get more information about a command'
) )
local -a fix_flags=( local -a fix_flags=(
'-fixtool=[specify fix analyzer]:analyzer:__go_fix_analyzers' '-fixtool=[specify fix analyzer]:analyzer:__golang_fix_analyzers'
'-diff[display diffs instead of rewriting files]' '-diff[display diffs instead of rewriting files]'
'-fixtool=[select analysis tool]:analyzer:' '-fixtool=[select analysis tool]:analyzer:'
'(- *)-V[print version and exit]' '(- *)-V[print version and exit]'
@ -464,7 +464,7 @@ case $state in
'-json[emit build output in JSON suitable for automated processing]' \ '-json[emit build output in JSON suitable for automated processing]' \
${build_flags[@]} \ ${build_flags[@]} \
${mod_flags[@]} \ ${mod_flags[@]} \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(clean) (clean)
@ -477,7 +477,7 @@ case $state in
'-fuzzcache[remove files stored in the Go build cache for fuzz testing]' \ '-fuzzcache[remove files stored in the Go build cache for fuzz testing]' \
${build_flags[@]} \ ${build_flags[@]} \
${mod_flags[@]} \ ${mod_flags[@]} \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(doc) (doc)
@ -489,7 +489,7 @@ case $state in
'-short[one-line representation for each symbol]' \ '-short[one-line representation for each symbol]' \
'-src[show the full source code for the symbol]' \ '-src[show the full source code for the symbol]' \
'-u[show docs for unexported and exported symbols and methods]' \ '-u[show docs for unexported and exported symbols and methods]' \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(env) (env)
@ -569,12 +569,12 @@ case $state in
) )
local -a exclude_from_w=(GOENV) local -a exclude_from_w=(GOENV)
__go_list_env_vars() { __golang_list_env_vars() {
# the parameter expansion strops off everything after the first [ # the parameter expansion strops off everything after the first [
_values -s ' ' -w 'environment variable' ${goenvvars[@]%%\[*} _values -s ' ' -w 'environment variable' ${goenvvars[@]%%\[*}
} }
# the ^ parameter expansion appends ": __go_envvarvals" to every element of goenvvars # the ^ parameter expansion appends ": __golang_envvarvals" to every element of goenvvars
# the :# parameter expansion removes all elements matching GOENV* # the :# parameter expansion removes all elements matching GOENV*
[[ $words[2] != '-w' ]] && _arguments \ [[ $words[2] != '-w' ]] && _arguments \
'-C[change to directory before running the command]: :_files -/' \ '-C[change to directory before running the command]: :_files -/' \
@ -582,15 +582,15 @@ case $state in
'-changed[prints only those settings whose effective value differs from the default value]' \ '-changed[prints only those settings whose effective value differs from the default value]' \
'-u[unset environment variables]' \ '-u[unset environment variables]' \
'-w[change the default setting of environment variables]' \ '-w[change the default setting of environment variables]' \
'*:[show environment variable]: __go_list_env_vars' || _values \ '*:[show environment variable]: __golang_list_env_vars' || _values \
-s ' ' -S "=" -w 'environment variable' ${^goenvvars:#GOENV*}": __go_envvarvals" -s ' ' -S "=" -w 'environment variable' ${^goenvvars:#GOENV*}": __golang_envvarvals"
;; ;;
(fix) (fix)
_arguments \ _arguments \
'-C[change to directory before running the command]: :_files -/' \ '-C[change to directory before running the command]: :_files -/' \
$fix_flags[@] \ $fix_flags[@] \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(fmt) (fmt)
@ -599,7 +599,7 @@ case $state in
'-n[print commands that would be executed]' \ '-n[print commands that would be executed]' \
'-x[print commands as they are executed]' \ '-x[print commands as they are executed]' \
'-mod=[set which download mode to use]:mode:(readonly vendor)' \ '-mod=[set which download mode to use]:mode:(readonly vendor)' \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(generate) (generate)
@ -610,7 +610,7 @@ case $state in
'-n[print the commands but do not run them]' \ '-n[print the commands but do not run them]' \
'-v[print the names of packages as they are compiled]' \ '-v[print the names of packages as they are compiled]' \
${build_flags[@]} \ ${build_flags[@]} \
"*:args:{ _alternative ':importpaths:__go_packages' _files }" "*:args:{ _alternative ':importpaths:__golang_packages' _files }"
;; ;;
(get) (get)
@ -620,13 +620,13 @@ case $state in
'-u[use the network to update the named packages]' \ '-u[use the network to update the named packages]' \
'-tool[instructs go to add a matching tool line to go.mod for each listed package]' \ '-tool[instructs go to add a matching tool line to go.mod for each listed package]' \
${build_flags[@]} \ ${build_flags[@]} \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(install) (install)
_arguments \ _arguments \
${build_flags[@]} \ ${build_flags[@]} \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(list) (list)
@ -642,7 +642,7 @@ case $state in
'-m[list modules instead of packages]' '-m[list modules instead of packages]'
${build_flags[@]} ${build_flags[@]}
${mod_flags[@]} ${mod_flags[@]}
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
) )
# -u and -versions are only available if -m is present on the commandline # -u and -versions are only available if -m is present on the commandline
if (($words[(I)-m])); then if (($words[(I)-m])); then
@ -684,7 +684,7 @@ case $state in
(init) (init)
# Use go packages as module name suggestion # Use go packages as module name suggestion
_arguments \ _arguments \
'*:module:__go_packages' '*:module:__golang_packages'
;; ;;
(tidy) (tidy)
_arguments \ _arguments \
@ -705,7 +705,7 @@ case $state in
_arguments \ _arguments \
'-m[treats the arguments as a list of modules]' \ '-m[treats the arguments as a list of modules]' \
'-vendor[exclude tests of dependencies]' \ '-vendor[exclude tests of dependencies]' \
'*:module:__go_packages' '*:module:__golang_packages'
;; ;;
esac esac
;; ;;
@ -716,7 +716,7 @@ case $state in
_arguments \ _arguments \
${build_flags[@]} \ ${build_flags[@]} \
'-exec[invoke the binary using xprog]:xporg' \ '-exec[invoke the binary using xprog]:xporg' \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(telemetry) (telemetry)
@ -803,7 +803,7 @@ case $state in
${build_flags[@]} \ ${build_flags[@]} \
'-exec[run test binary using xprog]:xprog' \ '-exec[run test binary using xprog]:xprog' \
'-o[compile test binary to named file]:file:_files' \ '-o[compile test binary to named file]:file:_files' \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
fi fi
;; ;;
@ -963,7 +963,7 @@ case $state in
(fix) (fix)
if [[ $words[2] == "help" ]]; then if [[ $words[2] == "help" ]]; then
__go_fix_analyzers __golang_fix_analyzers
else else
_arguments \ _arguments \
"*:args:{ _alternative ':subcommand:(help)' _files }" "*:args:{ _alternative ':subcommand:(help)' _files }"
@ -1119,7 +1119,7 @@ case $state in
'-add_comment=[free-form annotation to add to the profile]:comment' \ '-add_comment=[free-form annotation to add to the profile]:comment' \
'-diff_base=[source of base profile for comparison]:source:_files' \ '-diff_base=[source of base profile for comparison]:source:_files' \
'-base[show delta from this profile]:profile' \ '-base[show delta from this profile]:profile' \
'-symbolize=[controls source of symbol information]:source:__go_pprof_symbolize_types' \ '-symbolize=[controls source of symbol information]:source:__golang_pprof_symbolize_types' \
'-tls_cert=[TLS client certificate file for fetchign profile and symbols]:file:_files' \ '-tls_cert=[TLS client certificate file for fetchign profile and symbols]:file:_files' \
'-tls_key=[TLS private key file for fetching profile and symbols]:file:_files' \ '-tls_key=[TLS private key file for fetching profile and symbols]:file:_files' \
'-tls_ca=[TLS CA certs file for fetching profile and symbols]:file:_files' \ '-tls_ca=[TLS CA certs file for fetching profile and symbols]:file:_files' \
@ -1215,7 +1215,7 @@ case $state in
'-x[prints commands as they are executed]' \ '-x[prints commands as they are executed]' \
'-vettool[set a different analysis tool with alternative or additional checks]:prog:_files' \ '-vettool[set a different analysis tool with alternative or additional checks]:prog:_files' \
${build_flags[@]} \ ${build_flags[@]} \
'*:importpaths:__go_packages' '*:importpaths:__golang_packages'
;; ;;
(work) (work)