@@ -5,9 +5,15 @@ import (
5
5
"fmt"
6
6
"io"
7
7
"os"
8
+ "strings"
8
9
)
9
10
10
11
func genFishComp (buf * bytes.Buffer , name string , includeDesc bool ) {
12
+ // Variables should not contain a '-' or ':' character
13
+ nameForVar := name
14
+ nameForVar = strings .Replace (nameForVar , "-" , "_" , - 1 )
15
+ nameForVar = strings .Replace (nameForVar , ":" , "_" , - 1 )
16
+
11
17
compCmd := ShellCompRequestCmd
12
18
if ! includeDesc {
13
19
compCmd = ShellCompNoDescRequestCmd
@@ -38,12 +44,12 @@ function __%[1]s_perform_completion
38
44
__%[1]s_debug "emptyArg: $emptyArg"
39
45
40
46
if not type -q "$args[1]"
41
- # This can happen when "complete --do-complete %[1 ]s" is called when running this script.
47
+ # This can happen when "complete --do-complete %[2 ]s" is called when running this script.
42
48
__%[1]s_debug "Cannot find $args[1]. No completions."
43
49
return
44
50
end
45
51
46
- set requestComp "$args[1] %[2 ]s $args[2..-1] $emptyArg"
52
+ set requestComp "$args[1] %[3 ]s $args[2..-1] $emptyArg"
47
53
__%[1]s_debug "Calling $requestComp"
48
54
49
55
set results (eval $requestComp 2> /dev/null)
@@ -99,11 +105,11 @@ function __%[1]s_prepare_completions
99
105
__%[1]s_debug "Completions are: $__%[1]s_comp_results"
100
106
__%[1]s_debug "Directive is: $directive"
101
107
102
- set shellCompDirectiveError %[3 ]d
103
- set shellCompDirectiveNoSpace %[4 ]d
104
- set shellCompDirectiveNoFileComp %[5 ]d
105
- set shellCompDirectiveFilterFileExt %[6 ]d
106
- set shellCompDirectiveFilterDirs %[7 ]d
108
+ set shellCompDirectiveError %[4 ]d
109
+ set shellCompDirectiveNoSpace %[5 ]d
110
+ set shellCompDirectiveNoFileComp %[6 ]d
111
+ set shellCompDirectiveFilterFileExt %[7 ]d
112
+ set shellCompDirectiveFilterDirs %[8 ]d
107
113
108
114
if test -z "$directive"
109
115
set directive 0
@@ -158,24 +164,24 @@ end
158
164
# so we can properly delete any completions provided by another script.
159
165
# The space after the the program name is essential to trigger completion for the program
160
166
# and not completion of the program name itself.
161
- complete --do-complete "%[1 ]s " &> /dev/null
167
+ complete --do-complete "%[2 ]s " &> /dev/null
162
168
163
169
# Remove any pre-existing completions for the program since we will be handling all of them.
164
- complete -c %[1 ]s -e
170
+ complete -c %[2 ]s -e
165
171
166
172
# The order in which the below two lines are defined is very important so that __%[1]s_prepare_completions
167
173
# is called first. It is __%[1]s_prepare_completions that sets up the __%[1]s_comp_do_file_comp variable.
168
174
#
169
175
# This completion will be run second as complete commands are added FILO.
170
176
# It triggers file completion choices when __%[1]s_comp_do_file_comp is set.
171
- complete -c %[1 ]s -n 'set --query __%[1]s_comp_do_file_comp'
177
+ complete -c %[2 ]s -n 'set --query __%[1]s_comp_do_file_comp'
172
178
173
179
# This completion will be run first as complete commands are added FILO.
174
- # The call to __%[1]s_prepare_completions will setup both __%[1]s_comp_results abd __%[1]s_comp_do_file_comp.
180
+ # The call to __%[1]s_prepare_completions will setup both __%[1]s_comp_results and __%[1]s_comp_do_file_comp.
175
181
# It provides the program's completion choices.
176
- complete -c %[1 ]s -n '__%[1]s_prepare_completions' -f -a '$__%[1]s_comp_results'
182
+ complete -c %[2 ]s -n '__%[1]s_prepare_completions' -f -a '$__%[1]s_comp_results'
177
183
178
- ` , name , compCmd ,
184
+ ` , nameForVar , name , compCmd ,
179
185
ShellCompDirectiveError , ShellCompDirectiveNoSpace , ShellCompDirectiveNoFileComp ,
180
186
ShellCompDirectiveFilterFileExt , ShellCompDirectiveFilterDirs ))
181
187
}
0 commit comments