summary refs log tree commit diff
path: root/Completion/Unix/Command/_su
blob: daf301555f9bacb6397a08492d16fb8128819f4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#compdef su

local shell comp name usr base

[[ $words[2] != - ]]
(( base=$?+2 ))

if [[ CURRENT -eq base ]]; then
  _users && return
  usr=root
elif [[ CURRENT -ge base+1 ]]; then
  usr=$words[base]
else
  return
fi

shell="${${(M@)${(@f)$(</etc/passwd)}:#$usr*}##*:}"
compset -n $base
for name in $shell $shell:t -default-; do
  comp="$_comps[$name]"
  [[ -n "$comp" ]] && "$comp" && return
done