1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
# (C) 2011-2016 magicant
# Completion script for the "su" command.
# Supports GNU coreutils 8.10, util-linux 2.28.2, FreeBSD 8.2, OpenBSD 4.9,
# NetBSD 5.0, Mac OS X 10.6.4, SunOS 5.11, HP-UX 11i v3.
function completion/su {
case $("${WORDS[1]}" --version 2>/dev/null) in
(*'util-linux'*)
typeset type=util-linux gnu=true ul=true ;;
(*'GNU coreutils'*)
typeset type=GNU gnu=true ul= ;;
(*)
typeset type="$(uname 2>/dev/null)" gnu= ul= ;;
esac
typeset OPTIONS ARGOPT PREFIX
OPTIONS=()
case $type in (util-linux|GNU|Darwin|*BSD)
OPTIONS=("$OPTIONS" #>#
"f ${gnu:+--fast}; pass the -f option to the shell"
"l ${gnu:+--login}; invoke the command as a login shell"
"m ${gnu:+p --preserve-environment}; preserve all environment variables"
) #<#
case $type in (util-linux|GNU|OpenBSD)
OPTIONS=("$OPTIONS" #>#
"s: ${gnu:+--shell:}; specify the shell to be run"
) #<#
case $type in (util-linux|GNU)
OPTIONS=("$OPTIONS" #>#
"c: --command:; specify the command run instead of the shell"
"${ul:+h} --help; print help"
"${ul:+V} --version; print version info"
) #<#
;;
esac
esac
esac
case $type in (*BSD)
if [ "$(id -u 2>/dev/null)" -eq 0 ] 2>/dev/null; then
OPTIONS=("$OPTIONS" #>#
"c:; specify the login class"
) #<#
fi
esac
case $type in
(util-linux)
OPTIONS=("$OPTIONS" #>#
"g: --group:; specify the primary group to change to"
"G: --supp-group:; specify supplemental group to change to"
"--session-command:; like -c, but run in the same session"
) #<#
;;
(FreeBSD)
OPTIONS=("$OPTIONS" #>#
"s; set the MAC label to the default"
) #<#
;;
(OpenBSD)
OPTIONS=("$OPTIONS" #>#
"a:; specify the authentication method"
"L; loop till a successful authentication"
) #<#
;;
(NetBSD)
OPTIONS=("$OPTIONS" #>#
"d; like -l, but preserve the working directory"
"K; don't use Kerberos"
) #<#
;;
(HP-UX)
OPTIONS=("$OPTIONS" #>#
"d; use distributed computing environment (DCE)"
) #<#
;;
esac
command -f completion//parseoptions
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
(a)
if command -vf completion//bsd::completeauthmethod >/dev/null 2>&1 ||
. -AL completion/_bsd; then
command -f completion//bsd::completeauthmethod
fi
;;
(c|--command)
case $type in
(util-linux|GNU)
complete -P "$PREFIX" -c
;;
(*BSD)
if command -vf completion//bsd::completeauthclass >/dev/null 2>&1 ||
. -AL completion/_bsd; then
command -f completion//bsd::completeauthclass
fi
;;
esac
;;
([gG]|--*group)
complete -P "$PREFIX" -g
;;
(s|--shell|--session-command)
WORDS=()
command -f completion//reexecute -e
;;
(*)
command -f completion//getoperands
if [ "${WORDS[1]:-}" = - ]; then
WORDS=("${WORDS[2,-1]}")
fi
if [ "${WORDS[#]}" -le 0 ]; then
complete -P "$PREFIX" -u
else
WORDS=(sh "${WORDS[2,-1]}") #XXX assume POSIX shell
command -f completion//reexecute
fi
;;
esac
}
# vim: set ft=sh ts=8 sts=8 sw=8 et:
|