diff options
author | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-08-02 12:07:39 -0300 |
---|---|---|
committer | Lucas De Marchi <lucas.demarchi@intel.com> | 2013-08-02 12:07:39 -0300 |
commit | 48a409644199d5efff6d966cd72ccc7f5a06c2a5 (patch) | |
tree | 240d62fc1b1f6ab2b712d3655dddf31c5a0dd448 | |
parent | 80cf2c8f05813b04a5479746ce3ddaef00ea240d (diff) | |
download | kmod-48a409644199d5efff6d966cd72ccc7f5a06c2a5.tar.gz kmod-48a409644199d5efff6d966cd72ccc7f5a06c2a5.tar.bz2 kmod-48a409644199d5efff6d966cd72ccc7f5a06c2a5.zip |
shell-completion: Make options accept '=' as last char
-rw-r--r-- | shell-completion/bash/kmod | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/shell-completion/bash/kmod b/shell-completion/bash/kmod index 35e1040..f4da09d 100644 --- a/shell-completion/bash/kmod +++ b/shell-completion/bash/kmod @@ -24,23 +24,39 @@ __contains_word () { return 1 } +__is_opt () { + local prevprev=${COMP_WORDS[COMP_CWORD-2]} + local short="$1" long="$2" + + if [[ "$prev" = "$short" || "$prev" = "$long" ]]; then + declare -g cur=${cur#=} + return 0 + elif [[ "$prev" = "=" && "$prevprev" = "$long" ]]; then + return 0 + fi + + return 1 +} + _kmod_static_nodes () { - local OPTS='-o --output -f --format -h --help' + local OPTS='-o -f -h --help' + local OPTS_EQUAL='--output --format' local GROUP_FORMAT='human tmpfiles devname' - case "$prev" in - '-o' | '--output') + if __is_opt '-o' '--output'; then compopt -o filenames COMPREPLY=( $(compgen -f -- "$cur") ) return 0 - ;; - '-f' | '--format') + elif __is_opt '-f' '--format'; then COMPREPLY=( $(compgen -W "$GROUP_FORMAT" -- "$cur" ) ) return 0 - ;; - esac + fi + local cur=${COMP_WORDS[COMP_CWORD]} + + compopt -o nospace COMPREPLY=( $(compgen -W "$OPTS" -- "$cur") ) + COMPREPLY+=( $(compgen -W "$OPTS_EQUAL" -S= -- "$cur") ) } _kmod() { @@ -75,6 +91,12 @@ _kmod() { _kmod_${func} fi + # allow the space if there's only one completion and it doesn't end with + # '=' + if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != *"=" ]] ; then + compopt +o nospace + fi + return 0 } |