@@ -51,8 +51,7 @@ type autocompleteScript struct {
51
51
52
52
// autocompleteScripts regroups the autocomplete scripts for the different shells
53
53
// The key is the path of the shell.
54
- func autocompleteScripts (ctx context.Context ) map [string ]autocompleteScript {
55
- binaryName := core .ExtractBinaryName (ctx )
54
+ func autocompleteScripts (ctx context.Context , basename string ) map [string ]autocompleteScript {
56
55
homePath := core .ExtractUserHomeDir (ctx )
57
56
return map [string ]autocompleteScript {
58
57
"bash" : {
@@ -78,8 +77,8 @@ func autocompleteScripts(ctx context.Context) map[string]autocompleteScript {
78
77
return
79
78
}
80
79
complete -F _%[1]s %[1]s
81
- ` , binaryName ),
82
- CompleteScript : fmt .Sprintf (`eval "$(%s autocomplete script shell=bash)"` , binaryName ),
80
+ ` , basename ),
81
+ CompleteScript : fmt .Sprintf (`eval "$(%s autocomplete script shell=bash)"` , basename ),
83
82
ShellConfigurationFile : map [string ]string {
84
83
"darwin" : path .Join (homePath , ".bash_profile" ),
85
84
"linux" : path .Join (homePath , ".bashrc" ),
@@ -102,8 +101,8 @@ func autocompleteScripts(ctx context.Context) map[string]autocompleteScript {
102
101
complete --erase --command %[1]s;
103
102
complete --command %[1]s --no-files;
104
103
complete --command %[1]s --arguments '(%[1]s autocomplete complete fish -- (commandline) (commandline --cursor) (commandline --current-token) (commandline --current-process --tokenize --cut-at-cursor))';
105
- ` , binaryName ),
106
- CompleteScript : fmt .Sprintf (`eval (%s autocomplete script shell=fish)` , binaryName ),
104
+ ` , basename ),
105
+ CompleteScript : fmt .Sprintf (`eval (%s autocomplete script shell=fish)` , basename ),
107
106
ShellConfigurationFile : map [string ]string {
108
107
"darwin" : path .Join (homePath , ".config/fish/config.fish" ),
109
108
"linux" : path .Join (homePath , ".config/fish/config.fish" ),
@@ -124,8 +123,8 @@ func autocompleteScripts(ctx context.Context) map[string]autocompleteScript {
124
123
compadd "${opts[@]}" -- "${output[@]}"
125
124
}
126
125
compdef _%[1]s %[1]s
127
- ` , binaryName ),
128
- CompleteScript : fmt .Sprintf (`eval "$(%s autocomplete script shell=zsh)"` , binaryName ),
126
+ ` , basename ),
127
+ CompleteScript : fmt .Sprintf (`eval "$(%s autocomplete script shell=zsh)"` , basename ),
129
128
ShellConfigurationFile : map [string ]string {
130
129
"darwin" : path .Join (homePath , ".zshrc" ),
131
130
"linux" : path .Join (homePath , ".zshrc" ),
@@ -135,7 +134,8 @@ func autocompleteScripts(ctx context.Context) map[string]autocompleteScript {
135
134
}
136
135
137
136
type InstallArgs struct {
138
- Shell string
137
+ Shell string
138
+ Basename string
139
139
}
140
140
141
141
func autocompleteInstallCommand () * core.Command {
@@ -149,6 +149,13 @@ func autocompleteInstallCommand() *core.Command {
149
149
{
150
150
Name : "shell" ,
151
151
},
152
+ {
153
+ Name : "basename" ,
154
+ Default : func (ctx context.Context ) (value string , doc string ) {
155
+ resp := core .ExtractBinaryName (ctx )
156
+ return resp , resp
157
+ },
158
+ },
152
159
},
153
160
ArgsType : reflect .TypeOf (InstallArgs {}),
154
161
Run : InstallCommandRun ,
@@ -181,8 +188,8 @@ func InstallCommandRun(ctx context.Context, argsI interface{}) (i interface{}, e
181
188
}
182
189
183
190
shellName := filepath .Base (shellArg )
184
-
185
- script , exists := autocompleteScripts (ctx )[shellName ]
191
+ basename := argsI .( * InstallArgs ). Basename
192
+ script , exists := autocompleteScripts (ctx , basename )[shellName ]
186
193
if ! exists {
187
194
return nil , unsupportedShellError (shellName )
188
195
}
@@ -380,7 +387,8 @@ func autocompleteCompleteZshCommand() *core.Command {
380
387
}
381
388
382
389
type autocompleteShowArgs struct {
383
- Shell string
390
+ Shell string
391
+ Basename string
384
392
}
385
393
386
394
func autocompleteScriptCommand () * core.Command {
@@ -396,11 +404,19 @@ func autocompleteScriptCommand() *core.Command {
396
404
Name : "shell" ,
397
405
Default : core .DefaultValueSetter (os .Getenv ("SHELL" )),
398
406
},
407
+ {
408
+ Name : "basename" ,
409
+ Default : func (ctx context.Context ) (value string , doc string ) {
410
+ resp := core .ExtractBinaryName (ctx )
411
+ return resp , resp
412
+ },
413
+ },
399
414
},
400
415
ArgsType : reflect .TypeOf (autocompleteShowArgs {}),
401
416
Run : func (ctx context.Context , argsI interface {}) (i interface {}, e error ) {
402
417
shell := filepath .Base (argsI .(* autocompleteShowArgs ).Shell )
403
- script , exists := autocompleteScripts (ctx )[shell ]
418
+ basename := argsI .(* autocompleteShowArgs ).Basename
419
+ script , exists := autocompleteScripts (ctx , basename )[shell ]
404
420
if ! exists {
405
421
return nil , unsupportedShellError (shell )
406
422
}
0 commit comments