about summary refs log tree commit diff
path: root/Completion/User/_su
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/User/_su')
-rw-r--r--Completion/User/_su22
1 files changed, 22 insertions, 0 deletions
diff --git a/Completion/User/_su b/Completion/User/_su
new file mode 100644
index 000000000..e5bf09d80
--- /dev/null
+++ b/Completion/User/_su
@@ -0,0 +1,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