Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
improved svn completion for remote paths and urls
- X-seq: zsh-workers 27409
- From: Greg Klanderman <gak@xxxxxxxxxxxxxx>
- To: Zsh list <zsh-workers@xxxxxxx>
- Subject: improved svn completion for remote paths and urls
- Date: Sun, 15 Nov 2009 01:17:28 -0500
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Reply-to: gak@xxxxxxxxxxxxxx
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author