bash-completion/completions/update-alternatives

101 lines
2.6 KiB
Plaintext
Raw Normal View History

2009-05-27 18:51:09 +02:00
# bash completion for update-alternatives
have update-alternatives || return
2009-05-27 18:51:09 +02:00
_installed_alternatives()
{
2009-10-04 19:42:50 +02:00
local admindir
# find the admin dir
for i in alternatives dpkg/alternatives rpm/alternatives; do
[ -d /var/lib/$i ] && admindir=/var/lib/$i && break
done
for (( i=1; i < cword; i++ )); do
if [[ "${words[i]}" == --admindir ]]; then
admindir=${words[i+1]}
2009-10-04 19:42:50 +02:00
break
fi
done
COMPREPLY=( $( compgen -W '$( command ls $admindir )' -- "$cur" ) )
2009-05-27 18:51:09 +02:00
}
_update_alternatives()
{
local cur prev words cword
_init_completion || return
2009-05-27 18:51:09 +02:00
case $prev in
2009-12-09 20:55:45 +02:00
--altdir|--admindir)
_filedir -d
return 0
;;
--help|--usage|--version)
2009-12-09 20:55:45 +02:00
return 0
;;
2009-10-04 19:42:50 +02:00
esac
2009-05-27 18:51:09 +02:00
local mode args i
2009-10-04 19:42:50 +02:00
# find which mode to use and how many real args used so far
for (( i=1; i < cword; i++ )); do
if [[ "${words[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then
mode=${words[i]}
args=$(($cword - i))
2009-10-04 19:42:50 +02:00
break
fi
done
2009-05-27 18:51:09 +02:00
2009-10-04 19:42:50 +02:00
case $mode in
2009-12-09 20:55:45 +02:00
--install)
case $args in
1|3)
2009-12-09 20:55:45 +02:00
_filedir
;;
2)
_installed_alternatives
;;
4)
# priority - no completions
2009-12-09 20:55:45 +02:00
;;
*)
case $((args % 4)) in
0|2)
_filedir
;;
1)
COMPREPLY=( $( compgen -W '--slave' -- "$cur" ) )
;;
3)
_installed_alternatives
;;
esac
2009-12-09 20:55:45 +02:00
esac
;;
--remove|--set)
2009-12-09 20:55:45 +02:00
case $args in
1)
_installed_alternatives
;;
2)
_filedir
;;
esac
2009-10-04 19:42:50 +02:00
;;
--auto|--remove-all|--display|--config)
2009-12-09 20:55:45 +02:00
_installed_alternatives
2009-10-04 19:42:50 +02:00
;;
2009-12-09 20:55:45 +02:00
*)
COMPREPLY=( $( compgen -W '--verbose --quiet --help --version \
--altdir --admindir --install --remove --auto --display \
--config --set' -- "$cur" ) )
2009-10-04 19:42:50 +02:00
esac
2011-04-04 22:14:39 +03:00
} &&
2009-05-27 18:51:09 +02:00
complete -F _update_alternatives update-alternatives alternatives
# Local variables:
# mode: shell-script
2009-10-04 19:42:50 +02:00
# sh-basic-offset: 4
# sh-indent-comment: t
2009-10-04 19:42:50 +02:00
# indent-tabs-mode: nil
# End:
2009-10-04 19:42:50 +02:00
# ex: ts=4 sw=4 et filetype=sh