70ad5e3df8f7bed68aa6672029496926e632aedd
- Author
- Rayan Salhab <r.salhab@aiyexpertsolutions.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
fix(golang): complete go module tools (#13786)
Diff
1diff --git a/plugins/golang/_golang b/plugins/golang/_golang
2index 01b976b129d7018a3abfed55b9179ca77f7509d9..f34dbee24fb62f4f2d448288222e0c4c0625fb57 100644
3--- a/plugins/golang/_golang
4+++ b/plugins/golang/_golang
5@@ -15,6 +15,52 @@ __go_identifiers() {
6 compadd $(godoc -templates "$tmpl_path" ${words[-2]} 2> /dev/null)
7 }
8
9+__go_tool_commands() {
10+ local -a tools tool_commands
11+ local -A command_seen short_count
12+ local tool command
13+
14+ tools=("${(@f)$(go tool 2>/dev/null)}")
15+
16+ # Go 1.24+ lists module tools by package path, but also accepts unique
17+ # default binary names for those tools.
18+ for tool in "${tools[@]}"; do
19+ [[ -n $tool ]] || continue
20+
21+ (( command_seen[$tool]++ ))
22+
23+ if [[ $tool == */* ]]; then
24+ command=${tool:t}
25+
26+ if [[ $command == v[0-9]* && ${command#v} != *[^0-9]* ]] && (( ${command#v} > 1 )); then
27+ command=${${tool%/$command}:t}
28+ fi
29+
30+ (( short_count[$command]++ ))
31+ fi
32+ done
33+
34+ for tool in "${tools[@]}"; do
35+ [[ -n $tool ]] || continue
36+
37+ tool_commands+=("$tool")
38+
39+ if [[ $tool == */* ]]; then
40+ command=${tool:t}
41+
42+ if [[ $command == v[0-9]* && ${command#v} != *[^0-9]* ]] && (( ${command#v} > 1 )); then
43+ command=${${tool%/$command}:t}
44+ fi
45+
46+ if (( short_count[$command] == 1 && ! command_seen[$command] )); then
47+ tool_commands+=("$command")
48+ fi
49+ fi
50+ done
51+
52+ _values "go tool" "${tool_commands[@]}"
53+}
54+
55 _go() {
56 typeset -a commands build_flags
57 commands+=(
58@@ -208,7 +254,7 @@ _go() {
59 ;;
60 tool)
61 if (( CURRENT == 3 )); then
62- _values "go tool" $(go tool)
63+ __go_tool_commands
64 return
65 fi
66 case ${words[3]} in