diff options
author | Frantisek Tobias <frantisek.tobias@nic.cz> | 2024-10-15 12:41:52 +0200 |
---|---|---|
committer | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-12-20 22:24:22 +0100 |
commit | ae416c62217a5421638440996462dd432742a83b (patch) | |
tree | 97644de243949ba009a7860c8b5deb89d6f82d68 | |
parent | utils/shell-completion/client.bash: skip program name in COMP_WORDS (diff) | |
download | knot-resolver-ae416c62217a5421638440996462dd432742a83b.tar.xz knot-resolver-ae416c62217a5421638440996462dd432742a83b.zip |
utils/shell-completion/client.bash: compgen escape '--' arguments and minor adjustments
-rw-r--r-- | utils/shell-completion/client.bash | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/utils/shell-completion/client.bash b/utils/shell-completion/client.bash index 3a946dc4..a1c8290b 100644 --- a/utils/shell-completion/client.bash +++ b/utils/shell-completion/client.bash @@ -3,31 +3,22 @@ _kresctl_completion() { COMPREPLY=() - local cur prev opts + local words="" + local space_arg="" + local cur="${COMP_WORDS[COMP_CWORD]}" - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - - # check if there is a word is empty - # that means there is a space after last non-empty word - if [[ -z "$cur" ]] - then - # no word to complete, return all posible options - opts=$(kresctl completion --bash --space "${cmd_words[@]:1}") - else - opts=$(kresctl completion --bash "${cmd_words[@]:1}") + # if the current word is empty + # we need to inform the kresctl client about it + if [[ -z "$cur" ]]; then + space_arg="--space" fi - # if there is no completion from kresctl - # auto-complete just directories and files - if [[ -z "$opts" ]] - then - COMPREPLY=($(compgen -d -f "${cur}")) - else - COMPREPLY=( $(compgen -W "${opts}" ${cur}) ) - fi + # get words from the kresctl client + words=$(kresctl completion --bash ${space_arg} --args "${COMP_WORDS[@]:1}") + + COMPREPLY=($(compgen -W "${words}" -- "${cur}")) return 0 } -complete -o filenames -o dirnames -F _kresctl_completion kresctl +complete -o filenames -o dirnames -o nosort -F _kresctl_completion kresctl |