summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murzov <e-mail@date.by>2012-02-06 19:09:51 +0400
committerIgor Murzov <e-mail@date.by>2012-02-17 05:14:51 +0400
commitd2aedc83e143e7d506c8c5340dac4a820cc50076 (patch)
tree2809994d82d73933b58308e1120c03fd469d31f3
parent071ba93a0b9b5db37dc7c5b4b2423507d8f6b741 (diff)
downloadbash-completion-d2aedc83e143e7d506c8c5340dac4a820cc50076.tar.gz
su: Add linux-specific completion
-rw-r--r--bash_completion2
-rw-r--r--completions/Makefile.am1
-rw-r--r--completions/su35
3 files changed, 37 insertions, 1 deletions
diff --git a/bash_completion b/bash_completion
index a080b1c8..de52e2f2 100644
--- a/bash_completion
+++ b/bash_completion
@@ -59,7 +59,7 @@ complete -d pushd
# start of section containing compspecs that can be handled within bash
# user commands see only users
-complete -u su write chfn groups slay w sux runuser
+complete -u write chfn groups slay w sux runuser
# bg completes with stopped jobs
complete -A stopped -P '"%' -S '"' bg
diff --git a/completions/Makefile.am b/completions/Makefile.am
index c3efb273..507a6b73 100644
--- a/completions/Makefile.am
+++ b/completions/Makefile.am
@@ -293,6 +293,7 @@ bashcomp_DATA = a2x \
sshmitm \
sshow \
strace \
+ su \
sudo \
svk \
sync_members \
diff --git a/completions/su b/completions/su
new file mode 100644
index 00000000..df912306
--- /dev/null
+++ b/completions/su
@@ -0,0 +1,35 @@
+# bash completion for su(1) -*- shell-script -*-
+
+if [[ $OSTYPE != *linux* ]]; then
+ complete -u su # default completion
+ return
+fi
+
+_su() # linux-specific completion
+{
+ local cur prev words cword
+ _init_completion || return
+
+ case "$prev" in
+ -s|--shell)
+ _filedir
+ return
+ ;;
+ -c|--command)
+ local IFS=$'\n'
+ compopt -o filenames
+ COMPREPLY=( $( compgen -d -c -- "$cur" ) )
+ return
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '$( _parse_help "$1" --help )' -- "$cur" ) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
+ return
+ fi
+
+ COMPREPLY=( $( compgen -u -- "$cur" ) )
+} && complete -F _su su
+
+# ex: ts=4 sw=4 et filetype=sh