summaryrefslogtreecommitdiff
path: root/Completion/Unix/Command
diff options
context:
space:
mode:
authordana <dana@dana.is>2020-02-14 09:42:12 -0600
committerdana <dana@dana.is>2020-02-14 09:42:12 -0600
commitdd523255cc67780f2e073136d7f44978f96534a7 (patch)
tree7888dd6c66bb38012a3d55370156570bbda62b63 /Completion/Unix/Command
parent8037462895b4de98528a6b56c2f35d606150d3f3 (diff)
downloadzsh-dd523255cc67780f2e073136d7f44978f96534a7.tar.gz
zsh-dd523255cc67780f2e073136d7f44978f96534a7.zip
45423: _su: Improve arg handling, shell look-ups
Differences from ML post: * Properly fix escaping issue with $usr (needs unescaped first) * Make $shell emptiness check easier to read (per feedback)
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r--Completion/Unix/Command/_su45
1 files changed, 33 insertions, 12 deletions
diff --git a/Completion/Unix/Command/_su b/Completion/Unix/Command/_su
index 900905632..032f867f4 100644
--- a/Completion/Unix/Command/_su
+++ b/Completion/Unix/Command/_su
@@ -9,36 +9,44 @@ local shell usr
(( $words[(i)-(l|-login)] < CURRENT )) || args=( '-[use a login shell]' )
case $OSTYPE in
linux*)
+ # Some of these options only apply to util-linux, not shadow-utils
args=( -S $args
- '(-c --command --session-command *)'{-c,--command=}'[pass command to shell]:command string:_cmdstring'
+ '(-c --command --session-command *)'{-c+,--command=}'[pass command to shell]:command string:_cmdstring'
"(-c --command *)--session-command=[pass command to shell and don't create a new session]:command string:_cmdstring"
'(--fast -f)'{-f,--fast}'[pass -f to shell]'
'(-l --login -m -p --preserve-environment)'{-l,--login}'[use a login shell]'
'(-l --login -m -p --preserve-environment)'{-m,-p,--preserve-environment}"[don't reset environment]"
- '(-s --shell)'{-s,--shell=}'[run the specified shell]:shell:->shells'
+ '(-s --shell)'{-s+,--shell=}'[run the specified shell]:shell:->shells'
'(-)--help[display help information]'
'(-)--version[display version information]'
)
- (( EUID )) || args+=(
- '(-g --group)'{-g,--group=}'[specify primary group]:group:_groups'
- \*{-G,--supp-group=}'[specify supplemental group]:group:_groups'
+ (( $#_comp_priv_prefix || EUID == 0 )) && args+=(
+ '(-g --group)'{-g+,--group=}'[specify primary group]:group:_groups'
+ \*{-G+,--supp-group=}'[specify supplemental group]:group:_groups'
)
first="(--help --version)${first#???}"
;;
*bsd*|darwin*|dragonfly*)
args+=(
- '-c[use settings from specified login class]:class'
'-f[if the invoked shell is csh, prevent it from reading .cshrc]'
'(-m)-l[use a login shell]'
"(-l)-m[don't reset environment]"
)
;|
+ *bsd*|dragonfly*)
+ args+=(
+ '-c+[use settings from specified login class]:class'
+ )
+ ;|
freebsd*) args+=( '-s[set the MAC label]' ) ;;
openbsd*)
args+=(
- '(-K)-a[specify authentication type]:authentication type'
+ # See login.conf(5)
+ '(-K)-a+[specify authentication type]:authentication type:(
+ activ chpass crypto lchpass passwd radius reject skey snk token yubikey
+ )'
'(-a)-K[shorthand for -a passwd]'
- '-s[run the specified shell]:shell:->shells'
+ '-s+[run the specified shell]:shell:->shells'
'-L[loop until login succeeds]'
)
;;
@@ -57,13 +65,26 @@ fi
_arguments $args ${(e)first} "*:shell arguments:= ->rest" && return
-usr=${line[norm]/--/root}
-if (( $#opt_args[(i)-(s|-shell)] )); then
+usr=${${(Q)line[norm]}/--/root}
+# OpenBSD supports appending a log-in method to the user name, as in usr:radius
+[[ $OSTYPE == openbsd* ]] && usr=${usr%:*}
+
+# Normal users generally don't appear in passwd on macOS; try the Directory
+# Service first
+if [[ $OSTYPE == darwin* ]] && (( $+commands[dscl] )); then
+ shell=${"$(
+ _call_program shells dscl . -read /Users/${(q)usr} UserShell
+ )"#UserShell: }
+fi
+
+if [[ -n $shell ]]; then
+ : # Found above
+elif (( ${#${(@M)args:#*-s[+\[]*:*}} && $#opt_args[(i)-(s|-shell)] )); then
shell=${(v)opt_args[(i)-(s|-shell)]}
elif (( ${+commands[getent]} )); then
- shell="${$(_call_program shells getent passwd $usr)##*:}"
+ shell="${$(_call_program shells getent passwd ${(q)usr})##*:}"
else
- shell="${${(M@)${(@f)$(</etc/passwd)}:#$usr*}##*:}"
+ shell="${${(M@)${(@f)$(</etc/passwd)}:#${usr}:*}##*:}"
fi
case $state in