zsh-workers
 help / color / mirror / code / Atom feed
From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: zsh-workers@zsh.org
Subject: [PATCH] try to complete path in zfget
Date: Fri, 29 May 2015 18:11:19 +0800	[thread overview]
Message-ID: <20150529101119.GA1376@localhost.localdomain> (raw)

Hi,
Please review this patch. Thanks!

This patch will try to complete the path to a remote file recursively.

The only problem is that there are two categories listed:

% zfget dir/<tab>
remote directory
a  b  c
remote file
file1
---
 Functions/Zftp/zfget_match | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/Functions/Zftp/zfget_match b/Functions/Zftp/zfget_match
index 3a33c98..a440cac 100644
--- a/Functions/Zftp/zfget_match
+++ b/Functions/Zftp/zfget_match
@@ -9,17 +9,31 @@ if [[ $1 == $HOME || $1 == $HOME/* ]]; then
 fi
 
 if [[ $ZFTP_SYSTEM == UNIX* && $1 == */* ]]; then
-  setopt localoptions clobber
+  setopt localoptions clobber extendedglob
   local tmpf=${TMPPREFIX}zfgm$$
   zf_ln -fn =(<<<'') $tmpf || return 1
 
   if [[ -n $WIDGET ]]; then
-    local dir=${1:h}
+    local dir=${1%/*}
     [[ $dir = */ ]] || dir="$dir/"
     zftp ls -LF $dir >$tmpf
-    local reply
-    reply=(${${${(f)"$(<$tmpf)"}##$dir}%\*})
-    _wanted files expl 'remote file' compadd -P $dir - $reply
+    local reply1 reply2
+
+    # dirs in reply1, files in reply2
+    reply1=(${${(M)${${(f)"$(<$tmpf)"}##$dir}:#*/}%/})
+    reply2=(${${${${(f)"$(<$tmpf)"}##$dir}%\*}:#*/})
+
+    # try dir if ls -F doesn't work
+    if ! (($#reply1)); then
+      zftp dir $dir >$tmpf
+      reply1=(${(M)${(f)"$(<$tmpf)"}:#d([^[:space:]]##[[:space:]]##)(#c8)?##})
+      reply1=(${reply1/(#b)d([^[:space:]]##[[:space:]]##)(#c8)([^\/]##)\/#/$match[2]})
+
+      reply2=(${${(f)"$(<$tmpf)"}:#d([^[:space:]]##[[:space:]]##)(#c8)?##})
+      reply2=(${reply2/(#b)([^[:space:]]##[[:space:]]##)(#c8)(?##)/$match[2]})
+    fi
+    _wanted directories expl 'remote directory' compadd -S/ -q -P $dir - $reply1
+    _wanted files expl 'remote file' compadd -P $dir - $reply2
   else
     # On the first argument to ls, we usually get away with a glob.
     zftp ls "$1*$2" >$tmpf
-- 
1.9.3


                 reply	other threads:[~2015-05-29 10:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150529101119.GA1376@localhost.localdomain \
    --to=hanpt@linux.vnet.ibm.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).