This repository was archived by the owner on Sep 30, 2024. It is now read-only.
Commit 9d77d36 1 parent 63e9efd commit 9d77d36 Copy full SHA for 9d77d36
File tree 4 files changed +26
-12
lines changed
internal/usershell/autocomplete
4 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -239,10 +239,15 @@ func categoryAdditionalSGConfiguration() category {
239
239
}
240
240
shell := usershell .ShellType (ctx )
241
241
autocompletePath := usershell .AutocompleteScriptPath (sgHome , shell )
242
- if _ , err := os .Stat (autocompletePath ); err != nil {
242
+ completionScript , err := os .ReadFile (autocompletePath )
243
+ if err != nil {
243
244
return errors .Wrapf (err , "autocomplete script for shell %s not found" , shell )
244
245
}
245
246
247
+ if string (completionScript ) != usershell .AutocompleteScripts [shell ] {
248
+ return errors .Wrapf (err , "autocomplete script for shell %s is not up to date" , shell )
249
+ }
250
+
246
251
shellConfig := usershell .ShellConfigPath (ctx )
247
252
conf , err := os .ReadFile (shellConfig )
248
253
if err != nil {
Original file line number Diff line number Diff line change 1
1
# autocomplete scripts
2
2
3
- Autocomplete scripts are sourced from [ ` urfave/cli/autocomplete ` ] ( https://github.com/urfave/cli/tree/master /autocomplete ) .
3
+ Autocomplete scripts are sourced from [ ` urfave/cli/autocomplete ` ] ( https://github.com/urfave/cli/tree/main /autocomplete ) .
Original file line number Diff line number Diff line change 2
2
3
3
: ${PROG:= $(basename ${BASH_SOURCE} )}
4
4
5
+ # Macs have bash3 for which the bash-completion package doesn't include
6
+ # _init_completion. This is a minimal version of that function.
7
+ _cli_init_completion () {
8
+ COMPREPLY=()
9
+ _get_comp_words_by_ref " $@ " cur prev words cword
10
+ }
11
+
5
12
_cli_bash_autocomplete () {
6
13
if [[ " ${COMP_WORDS[0]} " != " source" ]]; then
7
- local cur opts base
14
+ local cur opts base words
8
15
COMPREPLY=()
9
16
cur=" ${COMP_WORDS[COMP_CWORD]} "
17
+ if declare -F _init_completion > /dev/null 2>&1 ; then
18
+ _init_completion -n " =:" || return
19
+ else
20
+ _cli_init_completion -n " =:" || return
21
+ fi
22
+ words=(" ${words[@]: 0: $cword } " )
10
23
if [[ " $cur " == " -" * ]]; then
11
- opts= $( ${COMP_WORDS[@] : 0 : $COMP_CWORD } ${cur} --generate-bash-completion)
24
+ requestComp= " ${words[*] } ${cur} --generate-bash-completion"
12
25
else
13
- opts= $( ${COMP_WORDS[@] : 0 : $COMP_CWORD } --generate-bash-completion)
26
+ requestComp= " ${words[*] } --generate-bash-completion"
14
27
fi
28
+ opts=$( eval " ${requestComp} " 2> /dev/null)
15
29
COMPREPLY=($( compgen -W " ${opts} " -- ${cur} ) )
16
30
return 0
17
31
fi
Original file line number Diff line number Diff line change 1
1
#compdef $PROG
2
2
3
- _CLI_ZSH_AUTOCOMPLETE_HACK=1
4
-
5
3
_cli_zsh_autocomplete() {
6
-
7
4
local -a opts
8
5
local cur
9
6
cur=${words[-1]}
10
7
if [[ "$cur" == "-"* ]]; then
11
- opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
8
+ opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
12
9
else
13
- opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
10
+ opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}")
14
11
fi
15
12
16
13
if [[ "${opts[1]}" != "" ]]; then
17
14
_describe 'values' opts
18
15
else
19
16
_files
20
17
fi
21
-
22
- return
23
18
}
24
19
25
20
compdef _cli_zsh_autocomplete $PROG
You can’t perform that action at this time.
0 commit comments