summary refs log tree commit diff
path: root/Completion/User/_su
blob: e5bf09d80efb59f37f8d7d50311a6ca6513025cc (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
  compgen -u && return
  usr=root
elif [[ CURRENT -ge base+1 ]]; then
  usr=$words[base]
else
  return
fi

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