From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4889 invoked by alias); 15 Nov 2009 06:26:08 -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: 27409 Received: (qmail 26504 invoked from network); 15 Nov 2009 06:25:56 -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.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received-SPF: none (ns1.primenet.com.au: domain at klanderman.net does not designate permitted sender hosts) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <19199.40184.570323.559889@gargle.gargle.HOWL> Date: Sun, 15 Nov 2009 01:17:28 -0500 From: Greg Klanderman To: Zsh list Subject: improved svn completion for remote paths and urls Reply-To: gak@klanderman.net X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 17) "Jumbo Shrimp" XEmacs Lucid (i386-redhat-linux) This improves the handling of completion for svn remote paths and repository locations (configured with the urls zstyle). I moved the completion of remote paths into a separate function, and fixed some precedence issues somewhat modeled after similar logic for hg completion. I added a few comments for things I found non-obvious, and added a missing $@ and a missing pair of quotes in _urls too. thanks, Greg Index: Completion/Unix/Command/_subversion =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_subversion,v retrieving revision 1.28 diff -u -r1.28 _subversion --- Completion/Unix/Command/_subversion 2 Jun 2009 08:46:56 -0000 1.28 +++ Completion/Unix/Command/_subversion 15 Nov 2009 05:54:25 -0000 @@ -205,32 +205,57 @@ (( ${(M)#${(f)_cache_svn_status[$key]}:#(#s)${~pat}*$REPLY} )) } -(( $+functions[_svn_urls] )) || -_svn_urls() { +(( $+functions[_svn_remote_paths] )) || +_svn_remote_paths() { local expl remfiles remdispf remdispd suf ret=1 - if [[ -prefix *: ]] && ! _urls && - zstyle -T ":completion:${curcontext}:" remote-access - then - remfiles=( ${(f)"$(svn list $IPREFIX${PREFIX%%[^./][^/]#} 2>/dev/null)"} ) - compset -P '*/' - compset -S '/*' || suf=file - remdispf=(${remfiles:#*/}) - remdispd=(${(M)remfiles:#*/}) - _tags files - while _tags; do - while _next_label files expl ${suf:-directory}; do - [[ -n $suf ]] && compadd -S ' ' -q "$@" "$expl[@]" -d remdispf $remdispf && ret=0 - compadd -S "${suf:+/}" -q "$@" "$expl[@]" -d remdispd ${remdispd%/} && ret=0 - done - (( ret )) || return 0 + [[ -prefix *://*/ ]] || return 1 + zstyle -T ":completion:${curcontext}:" remote-access || return 1 + + remfiles=( ${(f)"$(svn list $IPREFIX${PREFIX%%[^./][^/]#} 2>/dev/null)"} ) + (( $? == 0 )) || return 1 + + # you might consider trying to return early if $#remfiles is zero, + # but for whatever reason remfiles will always contain at least a + # single empty string; that case is handled correctly below. + + compset -P '*/' + compset -S '/*' || suf=file + remdispf=(${remfiles:#*/}) + remdispd=(${(M)remfiles:#*/}) + _tags files + while _tags; do + while _next_label files expl ${suf:-directory}; do + # add files, unless there is a '/' immediately to the right + [[ -n $suf ]] && + compadd -S ' ' -q "$@" "$expl[@]" -d remdispf $remdispf && ret=0 + # add directories; use empty suffix if there is a '/' immediately to the right + compadd -S "${suf:+/}" -q "$@" "$expl[@]" -d remdispd ${remdispd%/} && ret=0 done - else + (( ret )) || return 0 + done + + return 1 +} + +(( $+functions[_svn_urls] )) || +_svn_urls() { + local expl ret=1 + + # first try completing a remote path; if successful, we are all done.. + _svn_remote_paths && return 0 + + # allow configuring svn repository locations using the 'urls' zstyle. + # always attempt completion of these because then matcher-list styles + # which do substring matching will work correctly. + _urls -S/ && ret=0 + + if [[ ! -prefix *://? ]] ; then compset -S '[^:]*' _wanted url-schemas expl 'URL schema' compadd -S '' - \ file:// http:// https:// svn:// svn+ssh:// && ret=0 fi - + return ret } Index: Completion/Unix/Type/_urls =================================================================== RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_urls,v retrieving revision 1.11 diff -u -r1.11 _urls --- Completion/Unix/Type/_urls 30 Sep 2006 21:16:13 -0000 1.11 +++ Completion/Unix/Type/_urls 15 Nov 2009 05:54:25 -0000 @@ -48,7 +48,7 @@ if [[ $#urls -gt 1 || ( $#urls -eq 1 && ! -d $urls[1] ) ]]; then [[ $#urls -eq 1 && -f $urls[1] ]] && urls=( $(< $urls[1]) ) - _wanted urls expl 'URL' compadd -a urls && return 0 + _wanted urls expl 'URL' compadd "$@" -a urls && return 0 urls=() fi @@ -82,7 +82,7 @@ fi ;; file) - [[ -prefix //(127.0.0.1|localhost)/ ]] && compset -P //(127.0.0.1|localhost) + [[ -prefix //(127.0.0.1|localhost)/ ]] && compset -P '//(127.0.0.1|localhost)' [[ -prefix /// ]] && compset -P // if ! compset -P //; then _tags -C file files