* Subversion tab completion module
@ 2006-01-26 9:18 Andrew Ruder
2006-01-27 0:21 ` Vincent Lefevre
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Ruder @ 2006-01-26 9:18 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 899 bytes --]
Hello all,
I just thought I'd throw this out to anyone else who might be
interested. It is a simple (well, not so simple when its the first time
you've seen a completion module) hack on the _subversion completion
module that adds tab completion into a svn repository.
Example:
andy@looper ~ $ svn co http://aeruder.ath.cx:7777/svn/TalkSoup/<TAB>
branches/ historical/ packaging/ tags/ trunk/
And just in case you don't know how to use this, this is what I did.
Before the lines that look like:
autoload -U compinit
compinit
somewhere you should have a:
fpath=(~/.zshfunc $fpath)
autoload -U ~/.zshfunc/_*(:t)
Then just make a directory ~/.zshfunc and put the file in there.
I'm sure if there is anybody using subversion out there you'll find it
very handy, I know I have. Get back to me if you find any bugs. :)
Cheers,
Andrew Ruder
--
Andrew Ruder
http://www.aeruder.net
[-- Attachment #2: _subversion --]
[-- Type: text/plain, Size: 6682 bytes --]
#compdef svn svnadmin svnadmin-static=svnadmin
_remote_files () {
# There should be coloring based on all the different ls -F classifiers.
local expl remfiles remdispf remdispd args suf ret=1
if zstyle -T ":completion:${curcontext}:files" remote-access; then
remfiles=(${(M)${(f)"$(_call_program files svn list "${(Q)PREFIX%%[^./][^/]#}" 2>/dev/null)"}%%[^/]#(|/)})
compset -P '*/'
compset -S '/*' || suf='remote file'
remdispf=(${remfiles:#*/})
remdispd=(${(M)remfiles:#*/})
_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
else
_message -e remote-files 'remote file'
fi
}
_svn () {
_arguments -s \
'(-)--help[print help information]' \
'(- *)--version[print client version information]' \
'*::svn command:_svn_command'
}
_svnadmin () {
_arguments -s \
'(-)--help[print help information]' \
'(- *)--version[print client version information]' \
'*::svnadmin command:_svnadmin_command'
}
(( $+functions[_svn_controlled] )) ||
_svn_controlled() {
[[ -f ${(M)REPLY##*/}.svn/text-base/${REPLY##*/}.svn-base ]]
}
(( $+functions[_svn_deletedfiles] )) ||
_svn_deletedfiles() {
# Typical usage would be _files -g '.svn(/e:_svn_deletedfiles:)'
local cont controlled
reply=( )
[[ $REPLY = (*/|).svn ]] || return
controlled=( $REPLY/text-base/*.svn-base(N:r:t) )
for cont in ${controlled}; do
[[ -e $REPLY:h/$cont ]] || reply+=( ${REPLY%.svn}$cont )
done
}
(( $+functions[_svn_status] )) ||
_svn_status() {
local dir=$REPLY:h
local pat="${1:-([ADMR]|?M)}"
if (( ! $+_cache_svn_status[$dir] )); then
_cache_svn_status[$dir]="$(_call_program files svn status -N $dir)"
fi
(( ${(M)#${(f)_cache_svn_status[$dir]}:#(#s)${~pat}*$REPLY} ))
}
(( $+functions[_svn_urls] )) ||
_svn_urls() {
local expl
local myprefix
if [[ -prefix file:/// ]]; then
myprefix="${PREFIX#file://}"
myprefix="${(Q)myprefix%%[^./][^/]#}"
# Directory doesn't exist? prolly a repos
if ! [[ -d "$myprefix" ]]; then
_remote_files
# Take a wild guess that this is prolly a svn repos
elif [[ -e "$myprefix"/README.txt ]] &&
[[ -d "$myprefix"/hooks ]] &&
[[ -d "$myprefix"/locks ]]; then
_remote_files
# Ok, looks to be not a svn repos (yet)
else
_urls
fi
elif [[ -prefix *: ]]; then
_remote_files
else
compset -S '[^:]*'
_wanted url-schemas expl 'URL schema' compadd -S '' - \
file:// http:// https:// svn:// svn+ssh://
fi
}
(( $+functions[_svn_command] )) ||
_svn_command () {
local cmd
if (( ! $+_svn_cmds )); then
typeset -gA _svn_cmds
_svn_cmds=(
${=${(f)${${"$(LC_MESSAGES=C _call_program commands svn help)"#l#*Available subcommands:}%%Subversion is a tool*}}/(#s)[[:space:]]#(#b)([a-z]##)[[:space:]]#(\([a-z, ?]##\))#/$match[1] :$match[1]${match[2]:+:${${match[2]//[(),]}// /:}}:}
)
fi
if (( CURRENT == 1 )); then
_tags commands && { compadd "$@" -k _svn_cmds || compadd "$@" ${(s.:.)_svn_cmds} }
else
local curcontext="$curcontext"
cmd="${${(k)_svn_cmds[(R)*:$words[1]:*]}:-${(k)_svn_cmds[(i):$words[1]:]}}"
if (( $#cmd )); then
curcontext="${curcontext%:*:*}:svn-${cmd}:"
_svn_subcommand $cmd
else
_message "unknown svn command: $words[1]"
fi
fi
}
(( $+functions[_svn_subcommand] )) ||
_svn_subcommand () {
local subcmd _svn_subcmds _svn_subcmd_usage
typeset -A _cache_svn_status
_svn_subcmd_usage=${${(M)${(f)"$(LC_MESSAGES=C _call_program options svn help $1)"}:#usage:*}#usage: $1 }
_svn_subcmds=(
${${=${${${(M)${(f)"$(LC_MESSAGES=C _call_program options svn help $1)"##*Valid options:}:#* :*}%% #:*}/ arg/:arg:}/(#b)-([[:alpha:]]) \[--([a-z-]##)\](:arg:)#/(--$match[2])-$match[1]$match[3] (-$match[1])--$match[2]$match[3]}[2,-1]}
)
case $1 in;
add)
_svn_subcmds+=(
'*:file:_files -g "*(^e:_svn_controlled:)"'
)
;;
log)
_svn_subcmds+=(
'1: : _alternative "files:file:_files -g \*\(e:_svn_controlled:\)" "urls:URL:_svn_urls"'
'*:file:_files -g "*(e:_svn_controlled:)"'
)
;;
delete)
_svn_subcmds+=(
'*:file:_files -g ".svn(/e:_svn_deletedfiles:)"'
)
;;
revert|commit)
_svn_subcmds+=(
'*:file:_files -g "(.svn|*)(/e:_svn_deletedfiles:,e:_svn_status:)"'
)
;;
*)
case $_svn_subcmd_usage in
*(SRC|DST|TARGET|URL*PATH)*)
_svn_subcmds+=(
'*: : _alternative "files:file:_files" "urls:URL:_svn_urls"'
)
;;
*URL*) _svn_subcmds+=( ':URL:_svn_urls' ) ;;
*PATH*) _svn_subcmds+=( '*:file:_files' ) ;;
esac
;;
esac
_arguments "$_svn_subcmds[@]" && ret=0
return ret
}
(( $+functions[_svnadmin_command] )) ||
_svnadmin_command () {
local cmd
if (( ! $+_svnadmin_cmds )); then
typeset -gA _svnadmin_cmds
_svnadmin_cmds=(
${=${(f)${${"$(LC_MESSAGES=C _call_program commands svnadmin help)"#l#*Available subcommands:}}}/(#s)[[:space:]]#(#b)([a-z]##)[[:space:]]#(\([a-z, ?]##\))#/$match[1] :$match[1]${match[2]:+:${${match[2]//[(),]}// /:}}:}
)
fi
if (( CURRENT == 1 )); then
_tags commands && { compadd "$@" -k _svnadmin_cmds || compadd "$@" ${(s.:.)_svnadmin_cmds} }
else
local curcontext="$curcontext"
cmd="${${(k)_svnadmin_cmds[(R)*:$words[1]:*]}:-${(k)_svnadmin_cmds[(i):$words[1]:]}}"
if (( $#cmd )); then
curcontext="${curcontext%:*:*}:svnadmin-${cmd}:"
_svnadmin_subcommand $cmd
else
_message "unknown svnadmin command: $words[1]"
fi
fi
}
(( $+functions[_svnadmin_subcommand] )) ||
_svnadmin_subcommand () {
local subcmd _svnadmin_subcmds _svnadmin_subcmd_usage
_svnadmin_subcmd_usage=${${(M)${(f)"$(LC_MESSAGES=C _call_program options svnadmin help $1)"}:#$1: usage:*}#$1: usage: svnadmin $1 }
_svnadmin_subcmds=(
${${=${${${(M)${(f)"$(LC_MESSAGES=C _call_program options svnadmin help $1)"##*Valid options:}:#*:*}%% #:*}/ arg/:arg:}/(#b)-([[:alpha:]]) \[--([a-z-]##)\](:arg:)#/(--$match[2])-$match[1]$match[3] (-$match[1])--$match[2]$match[3]}[2,-1]}
)
[[ "$_svnadmin_subcmd_usage" == *REPOS_PATH* ]] &&
_svnadmin_subcmds=($_svnadmin_subcmds ":path:_files -/")
_arguments "$_svnadmin_subcmds[@]" && ret=0
return ret
}
_subversion () {
case $service in
(svn) _svn "$@" ;;
(svnadmin) _svnadmin "$@" ;;
esac
}
_subversion "$@"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Subversion tab completion module
2006-01-26 9:18 Subversion tab completion module Andrew Ruder
@ 2006-01-27 0:21 ` Vincent Lefevre
2006-01-27 0:57 ` Andrew Ruder
0 siblings, 1 reply; 5+ messages in thread
From: Vincent Lefevre @ 2006-01-27 0:21 UTC (permalink / raw)
To: zsh-users
On 2006-01-26 03:18:52 -0600, Andrew Ruder wrote:
> I'm sure if there is anybody using subversion out there you'll find it
> very handy, I know I have. Get back to me if you find any bugs. :)
As I said in the subversion users mailing-list:
There's a _subversion file distributed with zsh. Didn't you use this one?
For instance, your file contains in _svn_status:
local pat="${1:-([ADMR]|?M)}"
The one distributed in zsh contains the correct pattern:
local pat="${1:-([ADMR~]|?M)}"
( http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=330307 )
--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Subversion tab completion module
2006-01-27 0:21 ` Vincent Lefevre
@ 2006-01-27 0:57 ` Andrew Ruder
2006-01-27 3:41 ` Andrew Ruder
2006-01-27 22:46 ` Vincent Lefevre
0 siblings, 2 replies; 5+ messages in thread
From: Andrew Ruder @ 2006-01-27 0:57 UTC (permalink / raw)
To: zsh-users
On Fri, Jan 27, 2006 at 01:21:09AM +0100, Vincent Lefevre wrote:
> On 2006-01-26 03:18:52 -0600, Andrew Ruder wrote:
Vincent,
Thanks for the feedback, I appreciate it.
> > I'm sure if there is anybody using subversion out there you'll find it
> > very handy, I know I have. Get back to me if you find any bugs. :)
> As I said in the subversion users mailing-list:
Sorry, not subscribed there, only here :). Sorry I missed your reply.
I didn't want to crosspost per se, but I thought that both lists would
have a number of people perhaps interested.
> There's a _subversion file distributed with zsh. Didn't you use this one?
I checked out the CVS of zsh and verified that the _subversion
(particularly on the svn status line) has changed since what I made my
changes against. (Mine were against 4.2.5). I have attached a copy of
the module with the changes based against the latest CVS of _subversion
instead. I haven't tested it as much, but it seems to work fine, tell
me if you run into any more problems.
Cheers,
Andy
--
Andrew Ruder
http://www.aeruder.net
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Subversion tab completion module
2006-01-27 0:57 ` Andrew Ruder
@ 2006-01-27 3:41 ` Andrew Ruder
2006-01-27 22:46 ` Vincent Lefevre
1 sibling, 0 replies; 5+ messages in thread
From: Andrew Ruder @ 2006-01-27 3:41 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 295 bytes --]
On Thu, Jan 26, 2006 at 06:57:48PM -0600, Andrew Ruder wrote:
> ... I have attached a copy of the module with the changes based
> against the latest CVS of _subversion instead...
Yea.. right, about that. Its really attached this time. :)
Thanks,
Andy
--
Andrew Ruder
http://www.aeruder.net
[-- Attachment #2: _subversion --]
[-- Type: text/plain, Size: 7056 bytes --]
#compdef svn svnadmin svnadmin-static=svnadmin
_remote_files () {
# There should be coloring based on all the different ls -F classifiers.
local expl remfiles remdispf remdispd args suf ret=1
if zstyle -T ":completion:${curcontext}:files" remote-access; then
remfiles=(${(M)${(f)"$(_call_program files svn list "${(Q)PREFIX%%[^./][^/]#}" 2>/dev/null)"}%%[^/]#(|/)})
compset -P '*/'
compset -S '/*' || suf='remote file'
remdispf=(${remfiles:#*/})
remdispd=(${(M)remfiles:#*/})
_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
else
_message -e remote-files 'remote file'
fi
}
_svn () {
local curcontext="$curcontext" state line expl ret=1
_arguments -C \
'(-)--help[print help information]' \
'(- *)--version[print client version information]' \
'1: :->cmds' \
'*:: :->args' && ret=0
if [[ -n $state ]] && (( ! $+_svn_cmds )); then
typeset -gHA _svn_cmds
_svn_cmds=(
${=${(f)${${"$(LC_ALL=C _call_program commands svn help)"#l#*Available subcommands:}%%Subversion is a tool*}}/(#s)[[:space:]]#(#b)([a-z]##)[[:space:]]#(\([a-z, ?]##\))#/$match[1] :$match[1]${match[2]:+:${${match[2]//[(),]}// /:}}:}
)
fi
case $state in
cmds)
_wanted commands expl 'svn command' _svn_commands && ret=0
;;
args)
local cmd args usage
typeset -gHA _cache_svn_status
cmd="${${(k)_svn_cmds[(R)*:$words[1]:*]}:-${(k)_svn_cmds[(i):$words[1]:]}}"
if (( $#cmd )); then
curcontext="${curcontext%:*:*}:svn-${cmd}:"
usage=${${(M)${(f)"$(LC_ALL=C _call_program options svn help $cmd)"}:#usage:*}#usage:*$cmd] }
args=(
${=${${${(M)${(f)"$(LC_ALL=C _call_program options svn help $cmd)"##*Valid options:}:#* :*}%% #:*}/ arg/:arg:}/(#b)-([[:alpha:]]) \[--([a-z-]##)\](:arg:)#/(--$match[2])-$match[1]$match[3] (-$match[1])--$match[2]$match[3]}
)
case $cmd in;
add)
args+=(
'*:file:_files -g "*(^e:_svn_controlled:)"'
)
;;
commit)
args+=(
'*:file:_files -g "*(e:_svn_status:)"'
)
;;
delete)
args+=(
'*:file:_files -g ".svn(/e:_svn_deletedfiles:)"'
)
;;
help)
args+=(
'*::sub command:_svn_commands'
)
;;
log)
args+=(
'1: : _alternative "files:file:_files -g \*\(e:_svn_controlled:\)" "urls:URL:_svn_urls"'
'*:file:_files -g "*(e:_svn_controlled:)"'
)
;;
revert)
args+=(
'*:file:_files -g "(.svn|*)(/e:_svn_deletedfiles:,e:_svn_status:)"'
)
;;
*)
case $usage in
*(SRC|DST|TARGET|URL*PATH)*)
args+=(
'*: : _alternative "files:file:_files" "urls:URL:_svn_urls"'
)
;;
*URL*) args+=( ':URL:_svn_urls' ) ;;
*PATH*) args+=( '*:file:_files' ) ;;
esac
;;
esac
_arguments "$args[@]" && ret=0
else
_message "unknown svn command: $words[1]"
fi
;;
esac
return ret
}
_svnadmin () {
local curcontext="$curcontext" state line ret=1
_arguments -C \
'(-)--help[print help information]' \
'(- *)--version[print client version information]' \
'1: :->cmds' \
'*:: :->args' && ret=0
if [[ -n $state ]] && (( ! $+_svnadmin_cmds )); then
typeset -gHA _svnadmin_cmds
_svnadmin_cmds=(
${=${(f)${${"$(LC_ALL=C _call_program commands svnadmin help)"#l#*Available subcommands:}}}/(#s)[[:space:]]#(#b)([-a-z]##)[[:space:]]#(\([a-z, ?]##\))#/$match[1] :$match[1]${match[2]:+:${${match[2]//[(),]}// /:}}:}
)
fi
case $state in
cmds)
_wanted commands expl 'svnadmin command' _svnadmin_commands && ret=0
;;
args)
local cmd args usage
cmd="${${(k)_svnadmin_cmds[(R)*:$words[1]:*]}:-${(k)_svnadmin_cmds[(i):$words[1]:]}}"
if (( $#cmd )); then
curcontext="${curcontext%:*:*}:svnadmin-${cmd}:"
usage=${${(M)${(f)"$(LC_ALL=C _call_program options svnadmin help $cmd)"}:#$cmd: usage:*}#$cmd: usage: svnadmin $cmd }
args=(
${=${${${(M)${(f)"$(LC_ALL=C _call_program options svnadmin help $cmd)"##*Valid options:}:#*:*}%% #:*}/ arg/:arg:}/(#b)-([[:alpha:]]) \[--([a-z-]##)\](:arg:)#/(--$match[2])-$match[1]$match[3] (-$match[1])--$match[2]$match[3]}
)
if [[ $_svnadmin_subcmd_usage == *REPOS_PATH* ]]; then
args+=( ":path:_files -/" )
elif [[ $cmd = help ]]; then
args+=( "*:subcommand:_svnadmin_commands" )
fi
_arguments "$args[@]" && ret=0
else
_message "unknown svnadmin command: $words[1]"
fi
;;
esac
return ret
}
(( $+functions[_svn_controlled] )) ||
_svn_controlled() {
[[ -f ${(M)REPLY##*/}.svn/text-base/${REPLY##*/}.svn-base ]]
}
(( $+functions[_svn_deletedfiles] )) ||
_svn_deletedfiles() {
# Typical usage would be _files -g '.svn(/e:_svn_deletedfiles:)'
local cont controlled
reply=( )
[[ $REPLY = (*/|).svn ]] || return
controlled=( $REPLY/text-base/*.svn-base(N:r:t) )
for cont in ${controlled}; do
[[ -e $REPLY:h/$cont ]] || reply+=( ${REPLY%.svn}$cont )
done
}
(( $+functions[_svn_status] )) ||
_svn_status() {
local dir=$REPLY:h
local pat="${1:-([ADMR~]|?M)}"
if (( ! $+_cache_svn_status[$dir] )); then
_cache_svn_status[$dir]="$(_call_program files svn status -N $dir)"
fi
(( ${(M)#${(f)_cache_svn_status[$dir]}:#(#s)${~pat}*$REPLY} ))
}
(( $+functions[_svn_urls] )) ||
_svn_urls() {
local expl
local myprefix
if [[ -prefix file:/// ]]; then
myprefix="${PREFIX#file://}"
myprefix="${(Q)myprefix%%[^./][^/]#}"
# Directory doesn't exist? prolly a repos
if ! [[ -d "$myprefix" ]]; then
_remote_files
# Take a wild guess that this is prolly a svn repos
elif [[ -e "$myprefix"/README.txt ]] &&
[[ -d "$myprefix"/hooks ]] &&
[[ -d "$myprefix"/locks ]]; then
_remote_files
# Ok, looks to be not a svn repos (yet)
else
_urls
fi
elif [[ -prefix *: ]]; then
_remote_files
else
compset -S '[^:]*'
_wanted url-schemas expl 'URL schema' compadd -S '' - \
file:// http:// https:// svn:// svn+ssh://
fi
}
(( $+functions[_svn_commands] )) ||
_svn_commands() {
compadd "$@" -k _svn_cmds || compadd "$@" ${(s.:.)_svn_cmds}
}
(( $+functions[_svnadmin_command] )) ||
_svnadmin_commands() {
compadd "$@" -k _svnadmin_cmds || compadd "$@" ${(s.:.)_svnadmin_cmds}
}
_subversion () {
case $service in
(svn) _svn "$@" ;;
(svnadmin) _svnadmin "$@" ;;
esac
}
_subversion "$@"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Subversion tab completion module
2006-01-27 0:57 ` Andrew Ruder
2006-01-27 3:41 ` Andrew Ruder
@ 2006-01-27 22:46 ` Vincent Lefevre
1 sibling, 0 replies; 5+ messages in thread
From: Vincent Lefevre @ 2006-01-27 22:46 UTC (permalink / raw)
To: zsh-users
On 2006-01-26 18:57:48 -0600, Andrew Ruder wrote:
> On Fri, Jan 27, 2006 at 01:21:09AM +0100, Vincent Lefevre wrote:
> > As I said in the subversion users mailing-list:
>
> Sorry, not subscribed there, only here :). Sorry I missed your reply.
> I didn't want to crosspost per se, but I thought that both lists would
> have a number of people perhaps interested.
You could use Mutt's lists command before posting to the mailing-list.
Then Mutt would have generated a "Mail-Followup-To:" header with your
e-mail address in it, and my reply would have been Cc'ed to you.
> I checked out the CVS of zsh and verified that the _subversion
> (particularly on the svn status line) has changed since what I made my
> changes against. (Mine were against 4.2.5). I have attached a copy of
> the module with the changes based against the latest CVS of _subversion
> instead. I haven't tested it as much, but it seems to work fine, tell
> me if you run into any more problems.
Yes, a very big problem. I've tried it with a svn+ssh URL, and it is
very slow (if you don't cache anything, this isn't surprising). Now,
the main problem: I did a Ctrl-C, and zsh is now completely frozen.
zsh has executed the following process (which is still running):
vinc17 21381 0.0 0.1 41252 1476 q2 S+ 11:19PM 0:00.02 svn list svn+ssh://gforge/svn/mpfr/trunk/
which now has a child zombie:
vinc17 21405 0.0 0.0 0 0 q2 Z+ 1Jan70 0:00.00 (zsh)
Now, this is also a bug in Subversion (I'm going to report it) since
I can reproduce it (but not always) when typing the command from the
shell.
--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-01-27 22:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-26 9:18 Subversion tab completion module Andrew Ruder
2006-01-27 0:21 ` Vincent Lefevre
2006-01-27 0:57 ` Andrew Ruder
2006-01-27 3:41 ` Andrew Ruder
2006-01-27 22:46 ` Vincent Lefevre
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).