diff options
Diffstat (limited to 'completions/getent')
-rw-r--r-- | completions/getent | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/completions/getent b/completions/getent index 4c54a24..4310434 100644 --- a/completions/getent +++ b/completions/getent @@ -1,17 +1,19 @@ # bash completion for getent -*- shell-script -*- -_getent() +_comp_cmd_getent() { - local cur prev words cword split - _init_completion -s || return + local cur prev words cword was_split comp_args + _comp_initialize -s -- "$@" || return - local i db + local noargopts='!(-*|*[s]*)' + local i db="" has_db="" for ((i = 1; i < cword; i++)); do + # shellcheck disable=SC2254 case ${words[i]} in - --version | --usage | --help | -!(-*)[V?]) + --version | --usage | --help | -${noargopts}[V?]) return ;; - --service | -!(-*)s) + --service | -${noargopts}s) ((i++)) ;; -*) ;; @@ -19,35 +21,35 @@ _getent() *) # First non-option value is the db db=${words[i]} + has_db=set break ;; esac done - case ${db-} in + case $db in passwd) - COMPREPLY=($(compgen -u -- "$cur")) + _comp_compgen -- -u return ;; group) - COMPREPLY=($(compgen -g -- "$cur")) + _comp_compgen -- -g return ;; services) - COMPREPLY=($(compgen -s -- "$cur")) + _comp_compgen -- -s return ;; hosts) - COMPREPLY=($(compgen -A hostname -- "$cur")) + _comp_compgen -- -A hostname return ;; protocols | networks | ahosts | ahostsv4 | ahostsv6 | rpc) - COMPREPLY=($(compgen -W "$($1 $db | - awk '{ print $1 }')" -- "$cur")) + _comp_compgen_split -- "$("$1" "$db" | _comp_awk '{ print $1 }')" return ;; aliases | shadow | gshadow) - COMPREPLY=($(compgen -W "$($1 $db | cut -d: -f1)" -- "$cur")) + _comp_compgen_split -- "$("$1" "$db" | cut -d: -f1)" return ;; ethers | netgroup) @@ -55,23 +57,24 @@ _getent() ;; esac + # shellcheck disable=SC2254 case $prev in - -s | --service) + -${noargopts}s | --service) return ;; esac - $split && return + [[ $was_split ]] && return if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) + _comp_compgen_help [[ ${COMPREPLY-} == *= ]] && compopt -o nospace - elif [[ ! -v db ]]; then - COMPREPLY=($(compgen -W 'passwd group hosts services protocols - networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc - shadow gshadow' -- "$cur")) + elif [[ ! $has_db ]]; then + _comp_compgen -- -W 'passwd group hosts services protocols networks + ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc shadow + gshadow' fi } && - complete -F _getent getent + complete -F _comp_cmd_getent getent # ex: filetype=sh |