PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 0ms

/bash_completion.d/getent

http://github.com/brinkman83/bashrc
#! | 56 lines | 50 code | 6 blank | 0 comment | 0 complexity | d394036ecf826719368728ddc6f53cbc MD5 | raw file
 1# bash completion for getent
 2
 3have getent &&
 4_getent()
 5{
 6    local cur prev
 7
 8    COMPREPLY=()
 9    cur=`_get_cword`
10    prev=${COMP_WORDS[COMP_CWORD-1]}
11
12    case $prev in
13        passwd)
14            COMPREPLY=( $( compgen -u "$cur"  ) )
15            return 0
16            ;;
17        group)
18            COMPREPLY=( $( compgen -g "$cur"  ) )
19            return 0
20            ;;
21        services)
22            COMPREPLY=( $( compgen -s "$cur"  ) )
23            return 0
24            ;;
25        hosts)
26            COMPREPLY=( $( compgen -A hostname "$cur"  ) )
27            return 0
28            ;;
29        protocols|networks|ahosts|ahostsv4|ahostsv6|rpc)
30            COMPREPLY=( $( compgen -W "$( getent "$prev" | \
31                awk '{ print $1 }' )" -- "$cur" ) )
32            return 0
33            ;;
34        aliases|shadow)
35            COMPREPLY=( $( compgen -W "$( getent "$prev" | cut -d: -f1 )" \
36                -- "$cur" ) )
37            return 0
38            ;;
39    esac
40
41
42    if [ $COMP_CWORD -eq 1 ]; then
43        COMPREPLY=( $( compgen -W 'passwd group hosts services protocols \
44            networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc \
45            shadow' -- "$cur" ) )
46    fi
47} &&
48complete -F _getent getent
49
50# Local variables:
51# mode: shell-script
52# sh-basic-offset: 4
53# sh-indent-comment: t
54# indent-tabs-mode: nil
55# End:
56# ex: ts=4 sw=4 et filetype=sh