410 lines
8.6 KiB
Bash

# bash completion for shadow utils
_useradd()
{
local cur prev words cword split
_init_completion -s || return
# TODO: if -o/--non-unique is given, could complete on existing uids
# with -u/--uid
case $prev in
-c|--comment|-h|--help|-e|--expiredate|-f|--inactive|-k|--key|\
-p|--password|-u|--uid|-Z|--selinux-user)
return 0
;;
-b|--base-dir|-d|--home|-k|--skel)
_filedir -d
return 0
;;
-g|--gid)
_gids
COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $( compgen -g )' \
-- "$cur" ) )
return 0
;;
-G|--groups)
COMPREPLY=( $( compgen -g -- "$cur" ) )
return 0
;;
-s|--shell)
_shells
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
} &&
complete -F _useradd useradd
_usermod()
{
local cur prev words cword split
_init_completion -s || return
# TODO: if -o/--non-unique is given, could complete on existing uids
# with -u/--uid
case $prev in
-c|--comment|-d|--home|-e|--expiredate|-f|--inactive|-h|--help|\
-l|--login|-p|--password|-u|--uid|-Z|--selinux-user)
return 0
;;
-g|--gid)
_gids
COMPREPLY=( $( compgen -W '${COMPREPLY[@]} $( compgen -g )' \
-- "$cur" ) )
return 0
;;
-G|--groups)
COMPREPLY=( $( compgen -g -- "$cur" ) )
return 0
;;
-s|--shell)
_shells
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
# TODO: -U/--unlock, -p/--password, -L/--lock mutually exclusive
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
COMPREPLY=( $( compgen -u -- "$cur" ) )
} &&
complete -F _usermod usermod
_userdel()
{
local cur prev words cword
_init_completion || return
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
COMPREPLY=( $( compgen -u -- "$cur" ) )
} &&
complete -F _userdel userdel
_chage()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
-d|--lastday|-E|--expiredate|-h|--help|-I|--inactive|-m|--mindays|\
-M|--maxdays|-W|--warndays)
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
COMPREPLY=( $( compgen -u -- "$cur" ) )
} &&
complete -F _chage chage
_passwd()
{
local cur prev words cword
_init_completion || return
case $prev in
-n|--minimum|-x|--maximum|-w|--warning|-i|--inactive|-\?|--help|--usage)
return 0
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" )' -- "$cur" ) )
return 0
fi
_allowed_users
} &&
complete -F _passwd passwd
_chpasswd()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
-c|--crypt)
COMPREPLY=( $( compgen -W 'DES MD5 NONE SHA256 SHA512' \
-- "$cur" ) )
return 0
;;
-s|--sha-rounds)
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&
complete -F _chpasswd chpasswd
_newusers()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
-c|--crypt)
COMPREPLY=( $( compgen -W 'DES MD5 NONE SHA256 SHA512' \
-- "$cur" ) )
return 0
;;
-s|--sha-rounds)
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
_filedir
} &&
complete -F _newusers newusers
_pwck()
{
local cur prev words cword
_init_completion || return
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" )' -- "$cur" ) )
return 0
fi
_filedir
} &&
complete -F _pwck pwck
_groupadd()
{
local cur prev words cword split
_init_completion -s || return
# TODO: if -o/--non-unique is given, could complete on existing gids
# with -g/--gid
case $prev in
-g|--gid|-K|--key|-p|--password)
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&
complete -F _groupadd groupadd
_groupmod()
{
local cur prev words cword split
_init_completion -s || return
# TODO: if -o/--non-unique is given, could complete on existing gids
# with -g/--gid
case $prev in
-g|--gid|-h|--help|-n|--new-name|-p|--password)
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
COMPREPLY=( $( compgen -g -- "$cur" ) )
} &&
complete -F _groupmod groupmod
complete -g groupdel
_newgrp()
{
local cur prev words cword
_init_completion || return
if [[ "$cur" == "-" ]]; then
COMPREPLY=( - )
else
_allowed_groups "$cur"
fi
} &&
complete -F _newgrp newgrp
_gpasswd()
{
local cur prev words cword
_init_completion || return
case $prev in
-a|--add|-d|--delete|-A|--administrators|-M|--members)
COMPREPLY=( $( compgen -u -- "$cur" ) )
return 0
;;
esac
if [[ "$cur" == -* ]]; then
# TODO: only -A and -M can be combined
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
COMPREPLY=( $( compgen -g -- "$cur" ) )
} &&
complete -F _gpasswd gpasswd
_groupmems()
{
local cur prev words cword
_init_completion || return
case $prev in
-a|--add|-d|--delete)
COMPREPLY=( $( compgen -u -- "$cur" ) )
return 0
;;
-g|--group)
COMPREPLY=( $( compgen -g -- "$cur" ) )
return 0
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
} &&
complete -F _groupmems groupmems
_grpck()
{
local cur prev words cword
_init_completion || return
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" )' -- "$cur" ) )
return 0
fi
_filedir
} &&
complete -F _grpck grpck
_vipw()
{
local cur prev words cword
_init_completion || return
case $prev in
-h|--help)
return 0
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
return 0
fi
} &&
complete -F _vipw vipw vigr
_faillog()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
-h|--help|-l|--lock-time|-m|--maximum|-t|--time)
return 0
;;
-u|--user)
COMPREPLY=( $( compgen -u -- "$cur" ) )
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&
complete -F _faillog faillog
_lastlog()
{
local cur prev words cword split
_init_completion -s || return
case $prev in
-b|--before|-h|--help|-t|--time)
return 0
;;
-u|--user)
COMPREPLY=( $( compgen -u -- "$cur" ) )
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
fi
} &&
complete -F _lastlog lastlog
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh