From: Greg Klanderman <gak@klanderman.net>
To: Zsh list <zsh-workers@zsh.org>
Subject: improved svn completion for remote paths and urls
Date: Sun, 15 Nov 2009 01:17:28 -0500 [thread overview]
Message-ID: <19199.40184.570323.559889@gargle.gargle.HOWL> (raw)
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
reply other threads:[~2009-11-15 6:26 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=19199.40184.570323.559889@gargle.gargle.HOWL \
--to=gak@klanderman.net \
--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).