about summary refs log tree commit diff
path: root/Completion/Unix/Command
diff options
context:
space:
mode:
authorSimon Ruderich <rudi_s@users.sourceforge.net>2011-12-09 22:39:08 +0000
committerSimon Ruderich <rudi_s@users.sourceforge.net>2011-12-09 22:39:08 +0000
commitd374f2b1800d54d37a8e4c5299e824874a0489ed (patch)
tree5e3d67fa016e1cdc7890411fff2ad7590bd2b131 /Completion/Unix/Command
parent3e1146677f48dbeb697c2744266454d14d5289bb (diff)
downloadzsh-d374f2b1800d54d37a8e4c5299e824874a0489ed.tar.gz
zsh-d374f2b1800d54d37a8e4c5299e824874a0489ed.tar.xz
zsh-d374f2b1800d54d37a8e4c5299e824874a0489ed.zip
29918: Completion: Add new _remote_files() helper and use it to reduce code duplication.
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r--Completion/Unix/Command/_git35
-rw-r--r--Completion/Unix/Command/_rlogin29
-rw-r--r--Completion/Unix/Command/_rsync28
-rw-r--r--Completion/Unix/Command/_ssh38
4 files changed, 5 insertions, 125 deletions
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 4a830f281..702afe0e9 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5444,39 +5444,6 @@ __git_tree_files () {
 
 # Repository Argument Types
 
-# _remote_files
-_remote_files_git () {
-  # FIXME: these should be imported from _ssh
-  # TODO: this should take -/ to only get directories
-  # There should be coloring based on all the different ls -F classifiers.
-  local expl rempat remfiles remdispf remdispd args suf ret=1
-
-  if zstyle -T ":completion:${curcontext}:files" remote-access; then
-    zparseopts -D -E -a args p: 1 2 4 6 F:
-    if [[ -z $QIPREFIX ]]
-    then rempat="${PREFIX%%[^./][^/]#}\*"
-    else rempat="${(q)PREFIX%%[^./][^/]#}\*"
-    fi
-    remfiles=(${(M)${(f)"$(_call_program files ssh $args -a -x ${IPREFIX%:} ls -d1FL "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
-    compset -P '*/'
-    compset -S '/*' || suf='remote file'
-
-    remdispd=(${(M)remfiles:#*/})
-
-    _tags files
-    while _tags; do
-      while _next_label files expl ${suf:-remote directory}; do
-	compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
-	    ${(q)remdispd%/} && ret=0
-      done
-      (( ret )) || return 0
-    done
-    return ret
-  else
-    _message -e remote-files 'remote file'
-  fi
-}
-
 (( $+functions[__git_remote_repositories] )) ||
 __git_remote_repositories () {
   local service
@@ -5484,7 +5451,7 @@ __git_remote_repositories () {
   service= _ssh
 
   if compset -P '*:'; then
-    _remote_files_git
+    _remote_files --no-files -- ssh
   else
     _ssh_hosts -S:
   fi
diff --git a/Completion/Unix/Command/_rlogin b/Completion/Unix/Command/_rlogin
index 0d8355bfb..a04c6d068 100644
--- a/Completion/Unix/Command/_rlogin
+++ b/Completion/Unix/Command/_rlogin
@@ -1,32 +1,5 @@
 #compdef rlogin rsh remsh=rsh rcp
 
-_rcp_remote_files () {
-  # There should be coloring based on all the different ls -F classifiers.
-  local expl remfiles remdispf remdispd suf ret=1
-
-  if zstyle -T ":completion:${curcontext}:" remote-access; then
-    remfiles=(${(M)${(f)"$(rsh ${IPREFIX%:} ls -d1F ${(Q)PREFIX%%[^./][^/]#}\* 2>/dev/null)"}%%[^/]#(|/)})
-    compset -P '*/'
-    compset -S '/*' || suf='remote file'
-
-    remdispf=(${remfiles:#*/})
-    remdispd=(${(M)remfiles:#*/})
-
-    _tags files
-    while _tags; do
-      while _next_label files expl ${suf:-remote directory}; do
-        [[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
-	    ${(q)remdispf%[*=@|]} && ret=0 
-	compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
-	    ${(q)remdispd%/} && ret=0
-      done
-      (( ret )) || return 0
-    done
-  else
-    _message -e remote-files 'remote file'
-  fi
-}
-
 _rlogin () {
   case "$service" in
   rlogin)
@@ -65,7 +38,7 @@ _rlogin () {
 
     if [[ -n "$state" ]]; then
       if compset -P '*:'; then
-	_rcp_remote_files && ret=0
+	_remote_files -- rsh && ret=0
       elif compset -P '*@'; then
         _wanted hosts expl host _rlogin_hosts -S: && ret=0
       else
diff --git a/Completion/Unix/Command/_rsync b/Completion/Unix/Command/_rsync
index b999c1bbd..f24a06e47 100644
--- a/Completion/Unix/Command/_rsync
+++ b/Completion/Unix/Command/_rsync
@@ -59,33 +59,7 @@ elif compset -P 1 '*::' || compset -P 1 'rsync://*/'; then
 elif compset -P 'rsync://'; then
   _rsync_user_or_host / "$@"
 elif compset -P 1 '*:'; then
-
-  if zstyle -T ":completion:${curcontext}:files" remote-access; then
-    if [[ -z $QIPREFIX ]]
-    then rempat="${PREFIX%%[^./][^/]#}\*"
-    else rempat="${(q)PREFIX%%[^./][^/]#}\*"
-    fi
-    remfiles=(${(M)${(f)"$(_call_program files ssh -a -x ${IPREFIX%:} ls -d1FL "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
-    compset -P '*/'
-    compset -S '/*' || suf='remote file'
-
-    remdispf=(${remfiles:#*/})
-    remdispd=(${(M)remfiles:#*/})
-
-    _tags files
-    while _tags; do
-      while _next_label files expl ${suf:-remote directory}; do
-        [[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
-	    ${(q)remdispf%[*=@|]} && ret=0 
-	compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
-	    ${(q)remdispd%/} && ret=0
-      done
-      (( ret )) || return 0
-    done
-  else
-    _message -e remote-files 'remote file'
-  fi
-
+  _remote_files -- ssh
 else
   _rsync_user_or_host : "$@"
 fi
diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh
index bd23c3627..a6f2b40a2 100644
--- a/Completion/Unix/Command/_ssh
+++ b/Completion/Unix/Command/_ssh
@@ -5,40 +5,6 @@
 # TODO: update ssh-keygen (not based on 5.9)
 # TODO: sshd, ssh-keyscan, ssh-keysign
 
-
-_remote_files () {
-  # There should be coloring based on all the different ls -F classifiers.
-  local expl rempat remfiles remdispf remdispd args suf ret=1
-
-  if zstyle -T ":completion:${curcontext}:files" remote-access; then
-    zparseopts -D -E -a args p: 1 2 4 6 F:
-    if [[ -z $QIPREFIX ]]
-    then rempat="${PREFIX%%[^./][^/]#}\*"
-    else rempat="${(q)PREFIX%%[^./][^/]#}\*"
-    fi
-    remfiles=(${(M)${(f)"$(_call_program files ssh -o BatchMode=yes $args -a -x ${IPREFIX%:} ls -d1FL -- "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
-    compset -P '*/'
-    compset -S '/*' || suf='remote file'
-
-    remdispf=(${remfiles:#*/})
-    remdispd=(${(M)remfiles:#*/})
-
-    _tags files
-    while _tags; do
-      while _next_label files expl ${suf:-remote directory}; do
-        [[ -n $suf ]] && compadd "$@" "$expl[@]" -d remdispf \
-            ${(q)remdispf%[*=@|]} && ret=0 
-        compadd ${suf:+-S/} "$@" "$expl[@]" -d remdispd \
-            ${(q)remdispd%/} && ret=0
-      done
-      (( ret )) || return 0
-    done
-    return ret
-  else
-    _message -e remote-files 'remote file'
-  fi
-}
-
 _ssh () {
   local curcontext="$curcontext" state line expl common tmp cmds suf ret=1
   typeset -A opt_args
@@ -386,7 +352,7 @@ _ssh () {
       ;;
     file)
       if compset -P '*:'; then
-        _remote_files ${(kv)~opt_args[(I)-[FP1246]]/-P/-p} && ret=0
+        _remote_files -- ssh ${(kv)~opt_args[(I)-[FP1246]]/-P/-p} && ret=0
       elif compset -P '*@'; then
         suf=( -S '' )
         compset -S ':*' || suf=( -r: -S: )
@@ -400,7 +366,7 @@ _ssh () {
       ;;
     rfile)
       if compset -P '*:'; then
-        _remote_files && ret=0
+        _remote_files -- ssh && ret=0
       elif compset -P '*@'; then
         _wanted hosts expl host _ssh_hosts -r: -S: && ret=0
       else