diff options
author | Igor Murzov <e-mail@date.by> | 2012-01-09 16:25:00 +0400 |
---|---|---|
committer | Igor Murzov <e-mail@date.by> | 2012-01-09 16:25:00 +0400 |
commit | b515b0dd38158d990be1315db3f8d98f4cb39115 (patch) | |
tree | b060ee20f88402ac890e74a825dc7a396406e4b3 | |
parent | 694313874a8ef025c5bbbf2a57de058fb684e9b9 (diff) | |
parent | d0a14954ab45cb79aba9bff44d5ba910eac7925d (diff) | |
download | bash-completion-b515b0dd38158d990be1315db3f8d98f4cb39115.tar.gz |
Merge remote-tracking branch 'origin/sudo'
* origin/sudo:
sudoedit: New completion.
sudo: Fix option list parsing
sudo: Handle options (Alioth: #311414).
-rw-r--r-- | bash_completion | 2 | ||||
-rw-r--r-- | completions/.gitignore | 1 | ||||
-rw-r--r-- | completions/Makefile.am | 6 | ||||
-rw-r--r-- | completions/sudo | 51 | ||||
-rw-r--r-- | test/lib/completions/sudo.exp | 9 |
5 files changed, 68 insertions, 1 deletions
diff --git a/bash_completion b/bash_completion index 374e20c3..e3ff95f1 100644 --- a/bash_completion +++ b/bash_completion @@ -1730,7 +1730,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/.gitignore b/completions/.gitignore index 4e86f85c..0e234def 100644 --- a/completions/.gitignore +++ b/completions/.gitignore @@ -151,6 +151,7 @@ smbtree sparc-koji spovray stream +sudoedit tightvncviewer tracepath6 typeset diff --git a/completions/Makefile.am b/completions/Makefile.am index 7385e449..6e0f56f1 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -291,6 +291,7 @@ bashcomp_DATA = a2x \ sshmitm \ sshow \ strace \ + sudo \ svk \ sync_members \ sysbench \ @@ -500,6 +501,7 @@ CLEANFILES = \ sparc-koji \ spovray \ stream \ + sudoedit \ tightvncviewer \ tracepath6 \ typeset \ @@ -772,6 +774,10 @@ symlinks: rm -f $(targetdir)/$$file && \ $(LN_S) ssh $(targetdir)/$$file ; \ done + for file in sudoedit ; do \ + rm -f $(targetdir)/$$file && \ + $(LN_S) sudo $(targetdir)/$$file ; \ + done for file in tracepath6 ; do \ rm -f $(targetdir)/$$file && \ $(LN_S) tracepath $(targetdir)/$$file ; \ diff --git a/completions/sudo b/completions/sudo new file mode 100644 index 00000000..b13b7313 --- /dev/null +++ b/completions/sudo @@ -0,0 +1,51 @@ +# bash completion for sudo(8) -*- shell-script -*- + +_sudo() +{ + local cur prev words cword + _init_completion || return + + local i mode=normal + [[ $1 == *sudoedit ]] && mode=edit + + [[ $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 + if [[ ${COMP_WORDS[i]} == -e ]]; then + mode=edit + break + fi + [[ ${COMP_WORDS[i]} == -@(u|U|g|C|p) ]] && ((i++)) + 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 sudoedit + +# 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} { |