mirror of
https://github.com/spf13/cobra
synced 2025-05-05 04:47:22 +00:00
added keep order to default bash completions
This commit is contained in:
parent
6e475b6667
commit
87cd9437e1
1 changed files with 10 additions and 3 deletions
|
@ -81,6 +81,7 @@ __%[1]s_handle_go_custom_completion()
|
||||||
local shellCompDirectiveNoFileComp=%[5]d
|
local shellCompDirectiveNoFileComp=%[5]d
|
||||||
local shellCompDirectiveFilterFileExt=%[6]d
|
local shellCompDirectiveFilterFileExt=%[6]d
|
||||||
local shellCompDirectiveFilterDirs=%[7]d
|
local shellCompDirectiveFilterDirs=%[7]d
|
||||||
|
local shellCompDirectiveKeepOrder=%[8]d
|
||||||
|
|
||||||
local out requestComp lastParam lastChar comp directive args
|
local out requestComp lastParam lastChar comp directive args
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ __%[1]s_handle_go_custom_completion()
|
||||||
# Calling ${words[0]} instead of directly %[1]s allows to handle aliases
|
# Calling ${words[0]} instead of directly %[1]s allows to handle aliases
|
||||||
args=("${words[@]:1}")
|
args=("${words[@]:1}")
|
||||||
# Disable ActiveHelp which is not supported for bash completion v1
|
# Disable ActiveHelp which is not supported for bash completion v1
|
||||||
requestComp="%[8]s=0 ${words[0]} %[2]s ${args[*]}"
|
requestComp="%[9]s=0 ${words[0]} %[2]s ${args[*]}"
|
||||||
|
|
||||||
lastParam=${words[$((${#words[@]}-1))]}
|
lastParam=${words[$((${#words[@]}-1))]}
|
||||||
lastChar=${lastParam:$((${#lastParam}-1)):1}
|
lastChar=${lastParam:$((${#lastParam}-1)):1}
|
||||||
|
@ -127,6 +128,12 @@ __%[1]s_handle_go_custom_completion()
|
||||||
compopt -o nospace
|
compopt -o nospace
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
|
||||||
|
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||||
|
__%[1]s_debug "${FUNCNAME[0]}: activating keep order"
|
||||||
|
compopt -o nosort
|
||||||
|
fi
|
||||||
|
fi
|
||||||
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
||||||
if [[ $(type -t compopt) = "builtin" ]]; then
|
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||||
__%[1]s_debug "${FUNCNAME[0]}: activating no file completion"
|
__%[1]s_debug "${FUNCNAME[0]}: activating no file completion"
|
||||||
|
@ -398,7 +405,7 @@ __%[1]s_handle_word()
|
||||||
|
|
||||||
`, name, ShellCompNoDescRequestCmd,
|
`, name, ShellCompNoDescRequestCmd,
|
||||||
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
||||||
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, activeHelpEnvVar(name)))
|
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, ShellCompDirectiveKeepOrder, activeHelpEnvVar(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePostscript(buf io.StringWriter, name string) {
|
func writePostscript(buf io.StringWriter, name string) {
|
||||||
|
@ -437,7 +444,7 @@ func writePostscript(buf io.StringWriter, name string) {
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(`if [[ $(type -t compopt) = "builtin" ]]; then
|
WriteStringAndCheck(buf, fmt.Sprintf(`if [[ $(type -t compopt) = "builtin" ]]; then
|
||||||
complete -o default -F __start_%s %s
|
complete -o default -F __start_%s %s
|
||||||
else
|
else
|
||||||
complete -o default -o nospace -F __start_%s %s
|
complete -F __start_%s %s
|
||||||
fi
|
fi
|
||||||
|
|
||||||
`, name, name, name, name))
|
`, name, name, name, name))
|
||||||
|
|
Loading…
Add table
Reference in a new issue