about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-09-09 09:30:07 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-09-09 09:30:07 +0000
commit2aaebab3162c91cf44ea05e6dabae6c20894b5b0 (patch)
tree27e69802baa04b0468b6fd7bdb37c66febcfe8dc
parentb6dd9af94235f6944970c8c16b329c78d2f6f6da (diff)
downloadzsh-2aaebab3162c91cf44ea05e6dabae6c20894b5b0.tar.gz
zsh-2aaebab3162c91cf44ea05e6dabae6c20894b5b0.tar.xz
zsh-2aaebab3162c91cf44ea05e6dabae6c20894b5b0.zip
zsh-workers/7737
-rw-r--r--Completion/User/_ssh68
-rw-r--r--Completion/User/_users7
2 files changed, 69 insertions, 6 deletions
diff --git a/Completion/User/_ssh b/Completion/User/_ssh
index 1c0d61beb..a3a74e1cb 100644
--- a/Completion/User/_ssh
+++ b/Completion/User/_ssh
@@ -1,10 +1,21 @@
-#compdef ssh ssh-add ssh-agent ssh-keygen
+#compdef ssh slogin scp ssh-add ssh-agent ssh-keygen
 
-local state lstate line ret=1 expl
+local state lstate line ret=1 expl args
 typeset -A options
 
+args=()
+
+# ssh-opt is a pseudo-command used to complete ssh options for `scp -o'.
+
 case "$words[1]" in
-ssh)
+ssh|slogin)
+  args=(
+    ':remote host name:->userhost'
+    ':command: _command_names -e'
+    '*::args:->command'
+  )
+  ;&
+ssh-opt)
   _arguments -s \
     '-a[disable forwarding of authentication agent connection]' \
     '-c[select encryption cipher]:encryption cipher:(idea des 3des blowfish arcfour tss none)' \
@@ -25,9 +36,7 @@ ssh)
     '-C[compress all data]' \
     '-L[specify local port forwarding]:local port forwarding:->forward' \
     '-R[specify remote port forwarding]:remote port forwarding:->forward' \
-    ':remote host name:_hosts' \
-    ':command: _command_names -e' \
-    '*::args:->command' && ret=0
+    "$args[@]" && ret=0
 
   while [[ -n "$state" ]]; do
     lstate="$state"
@@ -113,6 +122,20 @@ ssh)
       _normal
       return
       ;;
+    userhost)
+      if compset -P '*@'; then
+        _description expl 'remote host name'
+        _hosts "$expl[@]"
+	return
+      else
+        _description expl 'remote host name'
+        _hosts "$expl[@]" && ret=0
+	if (( ! $+options[-l] )); then
+	  _description expl 'login name'
+	  _users "$expl[@]" -S@ && ret=0
+        fi
+      fi
+      ;;
     esac
 
     break;
@@ -120,6 +143,39 @@ ssh)
 
   return ret
   ;;
+scp)
+  _arguments -s \
+    '-c[select encryption cipher]:encryption cipher:(idea des 3des blowfish arcfour tss none)' \
+    '-P[specify port on remote host]:port number on remote host:' \
+    '-i[select identity file]:SSH identity file:_files' \
+    '-S[specify path to ssh]:path to ssh:_files -g \*\(\*\)' \
+    '-o[give SSH options]:options:->options' \
+    '-p[preserve modification times]' \
+    '-r[recursively copy directories]' \
+    '-v[verbose mode]' \
+    '-B[batch mode]' \
+    '-C[compress data]' \
+    '*:file:->file' && ret=0
+
+  if [[ "$state" = options ]]; then
+    compset -q
+    words=(ssh-opt "$words[@]" )
+    (( CURRENT++ ))
+    _ssh
+    return
+  elif [[ -n "$state" ]]; then
+    if compset -P '*:'; then
+      _files && ret=0
+    elif compset -P '*@'; then
+      _hosts -S: && ret=0
+    else
+      _files && ret=0
+      _hosts -S: && ret=0
+      _users -S@ && ret=0
+    fi
+  fi
+  return ret
+  ;;
 ssh-add)
   _arguments -s \
     '-p[read passphrase from stdin]' \
diff --git a/Completion/User/_users b/Completion/User/_users
index fc1e87e52..b115cccdc 100644
--- a/Completion/User/_users
+++ b/Completion/User/_users
@@ -1,6 +1,13 @@
 #autoload
 
+# If a parameter `users' exists and it is an array, we first try to
+# complete only to its elements.
+
 local expl
 
 _description expl user
+
+[[ "${(t)users}" = *array* ]] &&
+    compadd "$expl[@]" "$@" - "$users[@]" && return 0
+
 compgen "$@" "$expl[@]" -u