* improved svn completion for remote paths and urls
@ 2009-11-15 6:17 Greg Klanderman
0 siblings, 0 replies; only message in thread
From: Greg Klanderman @ 2009-11-15 6:17 UTC (permalink / raw)
To: Zsh list
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-11-15 6:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-15 6:17 improved svn completion for remote paths and urls Greg Klanderman
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).