diff --git a/CHANGES b/CHANGES index 05d01beb..163d047a 100644 --- a/CHANGES +++ b/CHANGES @@ -105,6 +105,7 @@ bash-completion (1.x) and zmore filename completions. * Add xz and compress support and more tarball filename extensions to rpmbuild -t*/--tarbuild completion. + * Improve sudo completion (Alioth: #311414). [ Todd Zullinger ] * Make yum complete on filenames after install, deplist, update and upgrade diff --git a/Makefile.am b/Makefile.am index d9036329..e26f0a5d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -121,6 +121,7 @@ bashcomp_DATA = contrib/ant \ contrib/snownews \ contrib/ssh \ contrib/strace \ + contrib/sudo \ contrib/svk \ contrib/sysctl \ contrib/sysv-rc \ diff --git a/bash_completion b/bash_completion index 806dacf5..022a7d12 100644 --- a/bash_completion +++ b/bash_completion @@ -1387,7 +1387,7 @@ _root_command() { PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin _command $1 $2 $3 } -complete -F _root_command $filenames sudo fakeroot really gksudo gksu kdesudo +complete -F _root_command $filenames fakeroot really gksudo gksu kdesudo _longopt() { diff --git a/contrib/sudo b/contrib/sudo new file mode 100644 index 00000000..fd35932b --- /dev/null +++ b/contrib/sudo @@ -0,0 +1,35 @@ +# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*- +# ex: ts=8 sw=8 noet filetype=sh +# +# bash completion for sudo + +have sudo && +_sudo() +{ + local cur prev + + COMPREPLY=() + cur=`_get_cword` + prev=${COMP_WORDS[COMP_CWORD-1]} + + # TODO: more option completions + + case $prev in + -e) + _filedir + return 0 + ;; + -u) + COMPREPLY=( $( compgen -u -- $cur ) ) + return 0 + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '-e -u' -- $cur ) ) + return 0 + fi + + _root_command $1 $2 $3 +} && +complete -F _sudo $filenames sudo