mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-06-05 05:03:16 +02:00
fix(golang): complete go module tools (#13786)
Some checks failed
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Some checks failed
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
This commit is contained in:
parent
b86a99da17
commit
70ad5e3df8
1 changed files with 47 additions and 1 deletions
|
|
@ -15,6 +15,52 @@ __go_identifiers() {
|
||||||
compadd $(godoc -templates "$tmpl_path" ${words[-2]} 2> /dev/null)
|
compadd $(godoc -templates "$tmpl_path" ${words[-2]} 2> /dev/null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__go_tool_commands() {
|
||||||
|
local -a tools tool_commands
|
||||||
|
local -A command_seen short_count
|
||||||
|
local tool command
|
||||||
|
|
||||||
|
tools=("${(@f)$(go tool 2>/dev/null)}")
|
||||||
|
|
||||||
|
# Go 1.24+ lists module tools by package path, but also accepts unique
|
||||||
|
# default binary names for those tools.
|
||||||
|
for tool in "${tools[@]}"; do
|
||||||
|
[[ -n $tool ]] || continue
|
||||||
|
|
||||||
|
(( command_seen[$tool]++ ))
|
||||||
|
|
||||||
|
if [[ $tool == */* ]]; then
|
||||||
|
command=${tool:t}
|
||||||
|
|
||||||
|
if [[ $command == v[0-9]* && ${command#v} != *[^0-9]* ]] && (( ${command#v} > 1 )); then
|
||||||
|
command=${${tool%/$command}:t}
|
||||||
|
fi
|
||||||
|
|
||||||
|
(( short_count[$command]++ ))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for tool in "${tools[@]}"; do
|
||||||
|
[[ -n $tool ]] || continue
|
||||||
|
|
||||||
|
tool_commands+=("$tool")
|
||||||
|
|
||||||
|
if [[ $tool == */* ]]; then
|
||||||
|
command=${tool:t}
|
||||||
|
|
||||||
|
if [[ $command == v[0-9]* && ${command#v} != *[^0-9]* ]] && (( ${command#v} > 1 )); then
|
||||||
|
command=${${tool%/$command}:t}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (( short_count[$command] == 1 && ! command_seen[$command] )); then
|
||||||
|
tool_commands+=("$command")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
_values "go tool" "${tool_commands[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
_go() {
|
_go() {
|
||||||
typeset -a commands build_flags
|
typeset -a commands build_flags
|
||||||
commands+=(
|
commands+=(
|
||||||
|
|
@ -208,7 +254,7 @@ _go() {
|
||||||
;;
|
;;
|
||||||
tool)
|
tool)
|
||||||
if (( CURRENT == 3 )); then
|
if (( CURRENT == 3 )); then
|
||||||
_values "go tool" $(go tool)
|
__go_tool_commands
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
case ${words[3]} in
|
case ${words[3]} in
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue