From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21858 invoked by alias); 29 May 2015 10:27:43 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35324 Received: (qmail 21071 invoked from network); 29 May 2015 10:27:41 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,TO_NO_BRKTS_PCNT autolearn=ham autolearn_force=no version=3.4.0 Date: Fri, 29 May 2015 18:11:19 +0800 From: Han Pingtian To: zsh-workers@zsh.org Subject: [PATCH] try to complete path in zfget Message-ID: <20150529101119.GA1376@localhost.localdomain> Mail-Followup-To: zsh-workers@zsh.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15052910-0033-0000-0000-000004A8BF7F 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/ 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