From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26520 invoked from network); 3 Oct 2008 16:28:18 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Oct 2008 16:28:18 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 46803 invoked from network); 3 Oct 2008 16:27:52 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Oct 2008 16:27:52 -0000 Received: (qmail 17830 invoked by alias); 3 Oct 2008 16:27:38 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25806 Received: (qmail 17800 invoked from network); 3 Oct 2008 16:27:33 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 3 Oct 2008 16:27:33 -0000 Received: from uucp.gnuu.de (banki.eumelnet.de [83.246.114.63]) by bifrost.dotsrc.org (Postfix) with ESMTP id B566C80308BA for ; Fri, 3 Oct 2008 18:27:24 +0200 (CEST) Received: by uucp.gnuu.de (Postfix, from userid 10) id B68FA488009; Fri, 3 Oct 2008 18:27:23 +0200 (CEST) X-DKIM: Sendmail DKIM Filter v2.5.2 uucp.gnuu.de B68FA488009 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=gnuu.de; s=banki; t=1223051243; i=@alea.gnuu.de; bh=GrDnFtWjHFZlgGyiy5cRL4+pFIA5ODGFH goOEsd2/sI=; h=To:From:Subject:Date:Message-ID:Mime-Version: Content-Type:Content-Transfer-Encoding:Sender; b=az/yvdv9nznz/QVbI ZJc9vueeFEGbaagAy0fRtiOZMj0BfO52HN/xR1c0r9RNmC9Ey66Gz/Ai/Zcrtergi1p 6J50fuDyeswB4/9eY9McHho1nww18yND26YEs6s1WrmnYaHodTAdmFadd4Ba5L4nQrQ AsAWDUIqVjmcDjTW/GW8= Received: from news by alea.gnuu.de with local (Exim 4.63) (envelope-from ) id 1Kln9z-00057U-7S for zsh-workers@sunsite.dk; Fri, 03 Oct 2008 18:05:43 +0200 To: zsh-workers@sunsite.dk Path: not-for-mail From: =?UTF-8?Q?J=C3=B6rg?= Sommer Newsgroups: local.mailinglist.zsh Subject: RFC: scp remote file completion with _multi_parts Date: Fri, 3 Oct 2008 16:05:43 +0000 (UTC) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: alea.gnuu.de 1223049943 19682 192.168.0.5 (3 Oct 2008 16:05:43 GMT) X-Complaints-To: usenet@alea.gnuu.de User-Agent: slrn/0.9.9 (Linux) Sender: news X-Virus-Scanned: ClamAV 0.92.1/8372/Thu Oct 2 17:21:47 2008 on bifrost X-Virus-Status: Clean Hi, my main goal is to get completion of abbreviated paths of remote files, e.g. scp server:/u/s/d/zs/cop gets scp server:/usr/share/doc/zsh/copyright Therefore, I propose this patch: diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh index c52b38c..46184d3 100644 --- a/Completion/Unix/Command/_ssh +++ b/Completion/Unix/Command/_ssh @@ -2,32 +2,15 @@ _remote_files () { # There should be coloring based on all the different ls -F classifiers. - local expl rempat remfiles remdispf remdispd args suf ret=1 + local expl rempat remfiles args 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' - - remdispf=(${remfiles:#*/}) - remdispd=(${(M)remfiles:#*/}) + rempat="${(q)PREFIX//\//*/}\*" + [[ $PREFIX = (.|..|)/* ]] && rempat=${PREFIX%%/*}/${rempat#*/} + remfiles=(${(f)"$(_call_program files ssh -o BatchMode=yes $args -a -x ${IPREFIX%:} ls -d1FL "$rempat" 2>/dev/null)"%[*=@|]}) - _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 + _wanted files expl 'remote file' _multi_parts $@ -- / remfiles else _message -e remote-files 'remote file' fi This patch has the following drawbacks: • The completion description doesn't contain the file type anymore, i.e. you don't get the suffixes @, |, * and =. • The directory separator / isn't automaticly removed from the end, if you insert a space. • It doesn't complete files with braces, but this might be a bug anywhere else, because: +_remote_files:7> rempat='/t\*/x\*/\*' +_remote_files:8> remfiles=+_remote_files:8> remfiles=( '/tmp/xx aa/ll12(45)' '/tmp/xx aa/zzz' ) +_remote_files:10> _wanted files expl 'remote file' _multi_parts -- / remfiles … +_multi_parts:94> compadd -O tmp1 -M 'r:|/=* r:|=* ' - 'll12(45)' zzz +_multi_parts:96> [[ 2 -eq 0 ]] +_multi_parts:99> [[ 2 -eq 1 ]] +_multi_parts:129> (( 2 )) … +_multi_parts:174> compadd -J -default- -S '' -p '/tmp/xx aa/' -M 'r:|/=* r:|=* ' - zzz Other changes of this patch: • The patch doesn't request a full directory listing of the remote directory, but only those entries beginning with the prefix, e.g. for /usr/share/doc/zs the remote ls isn't /usr/share/doc/* but /usr/share/doc/zs*. I think this is better than before. • It calls ssh with BatchMode=yes to prevent it from asking questions like confirming the fingerprint. What do you think? Are these drawbacks worth the completion of abbreviations? Bye, Jörg. -- “Unfortunately, the current generation of mail programs do not have checkers to see if the sender knows what he is talking about” (Andrew S. Tanenbaum)