diff options
author | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-12-23 09:26:44 +0100 |
---|---|---|
committer | Aleš Mrázek <ales.mrazek@nic.cz> | 2024-12-23 09:26:44 +0100 |
commit | cde3cfdfd26cfefc19f44d454aa671230eb42d5f (patch) | |
tree | d17ed198260f2ec4e8be3f7ae1b52cf4f622516d /utils/shell-completion/client.bash | |
parent | Merge !1643: kr_module_load(): clean up the code a bit (diff) | |
parent | distro: add bash completion to packages (diff) | |
download | knot-resolver-cde3cfdfd26cfefc19f44d454aa671230eb42d5f.tar.xz knot-resolver-cde3cfdfd26cfefc19f44d454aa671230eb42d5f.zip |
Merge branch 'kresctl-tab-completion' into 'master'
kresctl: implement tab completion
See merge request knot/knot-resolver!1622
Diffstat (limited to 'utils/shell-completion/client.bash')
-rw-r--r-- | utils/shell-completion/client.bash | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/utils/shell-completion/client.bash b/utils/shell-completion/client.bash index b3c19419..5cf66723 100644 --- a/utils/shell-completion/client.bash +++ b/utils/shell-completion/client.bash @@ -3,31 +3,27 @@ _kresctl_completion() { COMPREPLY=() - local cur prev opts + local args="" + local words="" + local cur="${COMP_WORDS[COMP_CWORD]}" + local opts=$(kresctl completion --bash --args "${COMP_WORDS[@]:1}") - 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 "${COMP_WORDS}") - else - opts=$(kresctl completion --bash "${COMP_WORDS}") - fi - - # if there is no completion from kresctl - # auto-complete just directories and files - if [[ -z "$opts" ]] - then - COMPREPLY=($(compgen -d -f "${cur}")) + # filter special opts + for opt in $opts + do + if [[ "$opt" == "#dirnames#" ]]; then + args="$args${args:+ }-d" + elif [[ "$opt" == "#filenames#" ]]; then + args="$args${args:+ }-f" + elif [[ "$opt" == "#nospace#" ]]; then + compopt -o nospace else - COMPREPLY=( $(compgen -W "${opts}" ${cur}) ) + words="$words${words:+ }$opt" fi + done + COMPREPLY=($(compgen $args -W "${words}" -- "${cur}")) return 0 } -complete -o filenames -o dirnames -F _kresctl_completion kresctl +complete -o nosort -F _kresctl_completion kresctl |