2009-05-27 18:51:09 +02:00
|
|
|
# bash completion for update-alternatives
|
|
|
|
|
|
|
|
have update-alternatives && {
|
|
|
|
_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 < COMP_CWORD; i++ )); do
|
|
|
|
if [[ "${COMP_WORDS[i]}" == --admindir ]]; then
|
|
|
|
admindir=${COMP_WORDS[i+1]}
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
COMPREPLY=( $( compgen -W '$( command ls $admindir )' -- "$cur" ) )
|
2009-05-27 18:51:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_update_alternatives()
|
|
|
|
{
|
2009-10-04 19:42:50 +02:00
|
|
|
local cur prev mode args i
|
2009-05-27 18:51:09 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
COMPREPLY=()
|
|
|
|
cur=`_get_cword`
|
|
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
2009-05-27 18:51:09 +02:00
|
|
|
|
2009-12-30 00:39:59 +01:00
|
|
|
case $prev in
|
2009-12-09 20:55:45 +02:00
|
|
|
--altdir|--admindir)
|
|
|
|
_filedir -d
|
|
|
|
return 0
|
|
|
|
;;
|
2009-12-09 21:23:29 +02:00
|
|
|
--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
|
|
|
|
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 < COMP_CWORD; i++ )); do
|
2009-12-09 21:23:29 +02:00
|
|
|
if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then
|
2009-10-04 19:42:50 +02:00
|
|
|
mode=${COMP_WORDS[i]}
|
|
|
|
args=$(($COMP_CWORD - i))
|
|
|
|
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
|
2009-12-09 21:23:29 +02:00
|
|
|
1|3)
|
2009-12-09 20:55:45 +02:00
|
|
|
_filedir
|
|
|
|
;;
|
|
|
|
2)
|
|
|
|
_installed_alternatives
|
|
|
|
;;
|
2009-12-09 21:23:29 +02:00
|
|
|
4)
|
|
|
|
# priority - no completions
|
2009-12-09 20:55:45 +02:00
|
|
|
;;
|
2009-12-09 21:23:29 +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
|
|
|
|
;;
|
2009-12-09 21:23:29 +02:00
|
|
|
--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
|
|
|
;;
|
2009-12-09 21:23:29 +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 \
|
2009-12-09 21:23:29 +02:00
|
|
|
--altdir --admindir --install --remove --auto --display \
|
|
|
|
--config --set' -- "$cur" ) )
|
2009-10-04 19:42:50 +02:00
|
|
|
esac
|
2009-05-27 18:51:09 +02:00
|
|
|
}
|
|
|
|
complete -F _update_alternatives update-alternatives alternatives
|
|
|
|
}
|
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
|