From d2aedc83e143e7d506c8c5340dac4a820cc50076 Mon Sep 17 00:00:00 2001 From: Igor Murzov Date: Mon, 6 Feb 2012 19:09:51 +0400 Subject: [PATCH] su: Add linux-specific completion --- bash_completion | 2 +- completions/Makefile.am | 1 + completions/su | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 completions/su 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