zsh: complete SSH directories
authorBrendan Cully <brendan@kublai.com>
Tue, 31 Oct 2006 14:53:08 -0800
changeset 3598 27121416f9a8
parent 3597 0d253ec988a6
child 3599 e00920b4f1cb
zsh: complete SSH directories
contrib/zsh_completion
--- a/contrib/zsh_completion	Tue Oct 31 12:05:47 2006 -0800
+++ b/contrib/zsh_completion	Tue Oct 31 14:53:08 2006 -0800
@@ -163,10 +163,33 @@
     'files:missing files:_hg_missing'
 }
 
+_hg_ssh_urls() {
+  if [[ -prefix */ ]]
+  then
+    if zstyle -T ":completion:${curcontext}:files" remote-access
+    then
+      local host=${PREFIX%%/*}
+      typeset -a remdirs
+      compset -p $(( $#host + 1 ))
+      local rempath=${(M)PREFIX##*/}
+      compset -P '*/'
+      remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}" 2> /dev/null)"}##*/}%/})
+      _describe -t directories 'remote directory' remdirs -S/
+    else
+      _message 'remote directory'
+    fi
+  else
+    _hosts -S/
+  fi
+}
+
 _hg_urls() {
   if compset -P bundle://
   then
     _files
+  elif compset -P ssh://
+  then
+    _hg_ssh_urls
   elif [[ -prefix *: ]]
   then
     _urls
@@ -190,7 +213,7 @@
 _hg_remote() {
   _alternative 'path-aliases:repository alias:_hg_paths' \
     'directories:directory:_files -/' \
-    'urls:URL schema:_hg_urls'
+    'urls:URL:_hg_urls'
 }
 
 # Common options