summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murzov <e-mail@date.by>2011-12-20 19:29:05 +0400
committerIgor Murzov <e-mail@date.by>2011-12-20 19:56:37 +0400
commit91a61afe59eeca58736e55745ae76ad6641a6a12 (patch)
tree5fce190fef522471d286b19fd3dd4d48d5f7e821
parent08a2264c8253496fa7d4abfa4ff969c5ccb7de3e (diff)
downloadbash-completion-91a61afe59eeca58736e55745ae76ad6641a6a12.tar.gz
sudo: Handle options (Alioth: #311414).
-rw-r--r--bash_completion2
-rw-r--r--completions/Makefile.am1
-rw-r--r--completions/sudo48
-rw-r--r--test/lib/completions/sudo.exp9
4 files changed, 59 insertions, 1 deletions
diff --git a/bash_completion b/bash_completion
index 6af67337..c2e59f38 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1727,7 +1727,7 @@ _root_command()
local root_command=$1
_command
}
-complete -F _root_command fakeroot gksu gksudo kdesudo really sudo
+complete -F _root_command fakeroot gksu gksudo kdesudo really
# Return true if the completion should be treated as running as root
_complete_as_root()
diff --git a/completions/Makefile.am b/completions/Makefile.am
index 43a59553..f8d53878 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -289,6 +289,7 @@ bashcomp_DATA = a2x \
sshmitm \
sshow \
strace \
+ sudo \
svk \
sync_members \
sysbench \
diff --git a/completions/sudo b/completions/sudo
new file mode 100644
index 00000000..621e59fd
--- /dev/null
+++ b/completions/sudo
@@ -0,0 +1,48 @@
+# bash completion for sudo(8) -*- shell-script -*-
+
+_sudo()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ local i mode=normal
+ for (( i=1; i <= COMP_CWORD; i++ )); do
+ if [[ ${COMP_WORDS[i]} != -* ]]; then
+ local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
+ local root_command=${COMP_WORDS[i]}
+ _command_offset $i
+ return
+ fi
+ [[ ${COMP_WORDS[i]} == -@(u|U|g|C|p) ]] && ((i++))
+ if [[ ${COMP_WORDS[i]} == -e ]]; then
+ mode=edit
+ break
+ fi
+ done
+
+ case "$prev" in
+ -u|-U)
+ COMPREPLY=( $( compgen -u -- "$cur" ) )
+ return
+ ;;
+ -g)
+ COMPREPLY=( $( compgen -g -- "$cur" ) )
+ return
+ ;;
+ -C|-p)
+ # argument required but no completions available
+ return
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-A -b -C -E -e -g -H -h -i -K -k -L -l -ll
+ -n -P -p -S -s -U -u -V -v' -- "$cur" ) )
+ return
+ fi
+ if [[ $mode == edit ]]; then
+ _filedir
+ fi
+} && complete -F _sudo sudo
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/test/lib/completions/sudo.exp b/test/lib/completions/sudo.exp
index 6108ddce..5fdb97f1 100644
--- a/test/lib/completions/sudo.exp
+++ b/test/lib/completions/sudo.exp
@@ -32,6 +32,15 @@ assert_complete_dir "default/" "sudo mount /dev/sda1 def" $::srcdir/fixtures/sha
sync_after_int
+set test "sudo -e should complete filenames and directories"
+set dir $::srcdir/fixtures/shared/default
+set files {foo foo.d/}
+assert_complete_dir $files "sudo -e -u root bar foo" $dir $test
+
+
+sync_after_int
+
+
# Find user/group suitable for testing.
set failed_find_unique_completion 0
foreach ug {user group} {