Add update-alternatives --set, --usage, and --slave completions, simplify some bits.

This commit is contained in:
Ville Skyttä 2009-12-09 21:23:29 +02:00
parent d68c8e508a
commit 09045a63b6
2 changed files with 23 additions and 20 deletions

View File

@ -24,7 +24,8 @@ bash-completion (2.x)
* Apply pine completion to alpine too.
* Remove many unnecessary short option completions where long ones exist.
* Improve configure, cvs, gkrellm, lftp, mdadm, modprobe, mplayer,
mysqladmin, screen, service, scp, ssh, and general hostname completions.
mysqladmin, screen, service, scp, ssh, update-alternatives, and general
hostname completions.
* Add abook and wtf completion, based on work by Raphaël Droz.
* Add jarsigner, k3b, lftpget, pack200 and unpack200 completions.
* Don't overwrite other host completions when completing from multiple

View File

@ -30,14 +30,14 @@ _update_alternatives()
_filedir -d
return 0
;;
--help|--version)
--help|--usage|--version)
return 0
;;
esac
# find which mode to use and how many real args used so far
for (( i=1; i < COMP_CWORD; i++ )); do
if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all) ]]; then
if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then
mode=${COMP_WORDS[i]}
args=$(($COMP_CWORD - i))
break
@ -47,18 +47,30 @@ _update_alternatives()
case $mode in
--install)
case $args in
1)
1|3)
_filedir
;;
2)
_installed_alternatives
;;
3)
_filedir
4)
# priority - no completions
;;
*)
case $((args % 4)) in
0|2)
_filedir
;;
1)
COMPREPLY=( $( compgen -W '--slave' -- "$cur" ) )
;;
3)
_installed_alternatives
;;
esac
esac
;;
--remove)
--remove|--set)
case $args in
1)
_installed_alternatives
@ -68,23 +80,13 @@ _update_alternatives()
;;
esac
;;
--auto)
_installed_alternatives
;;
--remove-all)
_installed_alternatives
;;
--display)
_installed_alternatives
;;
--config)
--auto|--remove-all|--display|--config)
_installed_alternatives
;;
*)
COMPREPLY=( $( compgen -W '--verbose --quiet --help --version \
--altdir --admindir' -- "$cur" ) \
$( compgen -W '--install --remove --auto --display \
--config' -- "$cur" ) )
--altdir --admindir --install --remove --auto --display \
--config --set' -- "$cur" ) )
esac
}
complete -F _update_alternatives update-alternatives alternatives