2010-08-22 11:16:33 +02:00
|
|
|
# bash completion for getent
|
2009-05-17 21:55:41 +02:00
|
|
|
|
2011-04-05 00:35:51 +03:00
|
|
|
have getent || return
|
|
|
|
|
2009-05-17 21:55:41 +02:00
|
|
|
_getent()
|
|
|
|
{
|
2011-04-20 17:02:27 +03:00
|
|
|
local cur prev words cword
|
2011-04-28 21:35:08 +03:00
|
|
|
_init_completion -n = || return
|
2009-05-17 21:55:41 +02:00
|
|
|
|
2011-04-28 21:35:08 +03:00
|
|
|
local split=false
|
|
|
|
_split_longopt && split=true
|
|
|
|
|
|
|
|
local i db
|
|
|
|
for (( i=1; i < cword; i++ )); do
|
|
|
|
case ${words[i]} in
|
|
|
|
-V|--version|--usage|-'?'|--help)
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
-s|--service)
|
|
|
|
(( i++ ))
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# First non-option value is the db
|
|
|
|
db=${words[i]}
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case $db in
|
2009-10-04 19:42:50 +02:00
|
|
|
passwd)
|
|
|
|
COMPREPLY=( $( compgen -u "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
group)
|
|
|
|
COMPREPLY=( $( compgen -g "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
services)
|
|
|
|
COMPREPLY=( $( compgen -s "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
hosts)
|
|
|
|
COMPREPLY=( $( compgen -A hostname "$cur" ) )
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
protocols|networks|ahosts|ahostsv4|ahostsv6|rpc)
|
2011-04-28 21:35:08 +03:00
|
|
|
COMPREPLY=( $( compgen -W "$( getent $db | \
|
2009-11-01 21:01:18 +02:00
|
|
|
awk '{ print $1 }' )" -- "$cur" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
return 0
|
|
|
|
;;
|
2011-04-28 20:52:50 +03:00
|
|
|
aliases|shadow|gshadow)
|
2011-04-28 21:35:08 +03:00
|
|
|
COMPREPLY=( $( compgen -W "$( getent $db | cut -d: -f1 )" \
|
2009-11-01 21:01:18 +02:00
|
|
|
-- "$cur" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
return 0
|
|
|
|
;;
|
2011-04-28 21:35:08 +03:00
|
|
|
ethers|netgroup)
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case $prev in
|
|
|
|
-s|--service)
|
|
|
|
return
|
|
|
|
;;
|
2009-10-04 19:42:50 +02:00
|
|
|
esac
|
2009-05-17 21:55:41 +02:00
|
|
|
|
2011-04-28 21:35:08 +03:00
|
|
|
$split && return
|
2009-05-17 21:55:41 +02:00
|
|
|
|
2011-04-28 21:35:08 +03:00
|
|
|
if [[ $cur == -* ]]; then
|
|
|
|
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
|
|
|
|
elif [[ -z $db ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=( $( compgen -W 'passwd group hosts services protocols \
|
|
|
|
networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc \
|
2011-04-28 20:52:50 +03:00
|
|
|
shadow gshadow' -- "$cur" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
fi
|
2009-05-17 21:55:41 +02:00
|
|
|
} &&
|
|
|
|
complete -F _getent getent
|
2009-10-01 20:54:51 +03:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
2009-10-04 19:42:50 +02:00
|
|
|
# sh-basic-offset: 4
|
2009-10-01 20:54:51 +03:00
|
|
|
# sh-indent-comment: t
|
2009-10-04 19:42:50 +02:00
|
|
|
# indent-tabs-mode: nil
|
2009-10-01 20:54:51 +03:00
|
|
|
# End:
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|