You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Martin Blais <ma...@gmail.com> on 2004/11/08 04:57:41 UTC

bash completion for subversion

hello

a little potential contribution: i took the bash completion file for
subversion and modified it so that it uses the output of subversion
itself to provide the completions, similar in idea to optcomplete
(http://furius.ca/optcomplete).  the idea is that the completions will
never go out-of-sync with whatever version of subversion you have
installed (well, unless the help format changes, which i estimate to
be unlikely).

cheers,

p.s. if someone thinks that this is worth adding to the codebase, feel
free to do so.

Re: bash completion for subversion

Posted by Philip Martin <ph...@codematters.co.uk>.
"Brian W. Fitzpatrick" <fi...@collab.net> writes:

>> >     # Possible expansions, without unambiguous abbreviations such as "up".
>> >     cmds=$($exe help| egrep '^   ' | sed -e 's/(//;s/)//;s/,//g')

As far as I can tell it's happening here.  The process that is using
memory/CPU is a child of the command line bash:

0  1000  4642  1404   9   0  2488 1376 pipe_w S+   pts/0      0:00 bash
1  1000  4761  4642  14   0 384804 383716 -   R+   pts/0      0:16 bash

PID 4642 is the command line while 4761 is using 380MB.  When I
interrupt completion using Ctrl-C 4761 goes away.  I don't know how to
debug it, strace just shows repeated calls to brk().

>> My real problem is that I can't get it to work.  The things that don't
>> work are:
>> 
>>    $ svn <TAB>
>> 
>> The shell uses CPU and memory (it goes into swap) but doesn't generate
>> a list of commands.  Command completion fails in the same way:
>> 
>>    $ svn che<TAB>
>
> Odd.  Both of these work for me.  Here's my version info:
>
> $ bash --version
> GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)

GNU bash, version 2.05a.0(1)-release (i386-pc-linux-gnu)

This is Debian stable.

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: bash completion for subversion

Posted by "Brian W. Fitzpatrick" <fi...@collab.net>.
On Mon, 2004-11-08 at 13:24, Philip Martin wrote:
> Martin Blais <ma...@gmail.com> writes:
> 
> > a little potential contribution: i took the bash completion file for
> > subversion and modified it so that it uses the output of subversion
> > itself to provide the completions, similar in idea to optcomplete
> > (http://furius.ca/optcomplete).  the idea is that the completions will
> > never go out-of-sync with whatever version of subversion you have
> > installed (well, unless the help format changes, which i estimate to
> > be unlikely).
> >
> > cheers,
> >
> > p.s. if someone thinks that this is worth adding to the codebase, feel
> > free to do so.
> 
> I like the idea, but when I try to use it bash goes awol, using more
> and more memory until I interrupt the completion.
> 
> > #!/bin/sh
> 
> Why?  Doesn't it need to be sourced by a shell, rather than executed?
> 
> > #
> > # $Id: bashrc,v 1.1 2004/11/08 00:09:46 blais Exp $
> > # $Source: /u/blais/cvsroot/oversion/etc/bashrc,v $
> > #
> > # Author: Martin Blais
> > # Date: 2004-11-07
> > #
> >
> > _svn_common ()
> > {
> >     exe=$1
> >     local cur cmds cmdOpts pOpts mOpts rOpts qOpts nOpts optsParam opt
> >     local helpCmds optBase i
> 
> A lot of these are now not used and could be removed.
> 
> >     
> >     COMPREPLY=()
> >     cur=${COMP_WORDS[COMP_CWORD]}
> >     
> >     # Possible expansions, without unambiguous abbreviations such as "up".
> >     cmds=$($exe help| egrep '^   ' | sed -e 's/(//;s/)//;s/,//g')
> >
> >     if [[ $COMP_CWORD -eq 1 ]] ; then
> > 	COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
> > 	return 0
> >     fi
> >
> >     # find the current command
> >     cmd=${COMP_WORDS[1]}
> >
> >     # options that require a parameter
> >     helpOut=$($exe $cmd --help | egrep '^  .* : ' | \
> > 	      sed -e 's/[ ]*:.*//;s/\[//;s/\]//;')
> >
> >     optsParam=$(echo "$helpOut" | grep arg$)
> >     optsParam=$(echo $optsParam | sed -e 's/ arg//g;s/ /|/g')
> >
> >     # if not typing an option, or if the previous option required a
> >     # parameter, then fallback on ordinary filename expansion
> >     helpCmds='help|--help|h|\?'
> >     if [[ ${COMP_WORDS[1]} != @($helpCmds) ]] && \
> >        [[ "$cur" != -* ]] || \
> >        [[ ${COMP_WORDS[COMP_CWORD-1]} == @($optsParam) ]] ; then
> >     	return 0
> >     fi
> >
> >     cmdOpts=$(echo $helpOut | sed -e 's/ arg//g')
> >
> >     COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
> >
> >     return 0
> > }
> >
> > _svn_new ()
> > {
> >     _svn_common "svn"
> > }
> > complete -F _svn_new -o default svn
> >
> > _svnadmin_new ()
> > {
> >     _svn_common "svnadmin"
> > }
> 
> You have also removed the alternatives/exclusives handling, I'd like
> to see that back.
> 
> My real problem is that I can't get it to work.  The things that don't
> work are:
> 
>    $ svn <TAB>
> 
> The shell uses CPU and memory (it goes into swap) but doesn't generate
> a list of commands.  Command completion fails in the same way:
> 
>    $ svn che<TAB>

Odd.  Both of these work for me.  Here's my version info:

$ bash --version
GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)


> but option expansion works fine:

Same here.

-Fitz


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: bash completion for subversion

Posted by Philip Martin <ph...@codematters.co.uk>.
Martin Blais <ma...@gmail.com> writes:

> a little potential contribution: i took the bash completion file for
> subversion and modified it so that it uses the output of subversion
> itself to provide the completions, similar in idea to optcomplete
> (http://furius.ca/optcomplete).  the idea is that the completions will
> never go out-of-sync with whatever version of subversion you have
> installed (well, unless the help format changes, which i estimate to
> be unlikely).
>
> cheers,
>
> p.s. if someone thinks that this is worth adding to the codebase, feel
> free to do so.

I like the idea, but when I try to use it bash goes awol, using more
and more memory until I interrupt the completion.

> #!/bin/sh

Why?  Doesn't it need to be sourced by a shell, rather than executed?

> #
> # $Id: bashrc,v 1.1 2004/11/08 00:09:46 blais Exp $
> # $Source: /u/blais/cvsroot/oversion/etc/bashrc,v $
> #
> # Author: Martin Blais
> # Date: 2004-11-07
> #
>
> _svn_common ()
> {
>     exe=$1
>     local cur cmds cmdOpts pOpts mOpts rOpts qOpts nOpts optsParam opt
>     local helpCmds optBase i

A lot of these are now not used and could be removed.

>     
>     COMPREPLY=()
>     cur=${COMP_WORDS[COMP_CWORD]}
>     
>     # Possible expansions, without unambiguous abbreviations such as "up".
>     cmds=$($exe help| egrep '^   ' | sed -e 's/(//;s/)//;s/,//g')
>
>     if [[ $COMP_CWORD -eq 1 ]] ; then
> 	COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
> 	return 0
>     fi
>
>     # find the current command
>     cmd=${COMP_WORDS[1]}
>
>     # options that require a parameter
>     helpOut=$($exe $cmd --help | egrep '^  .* : ' | \
> 	      sed -e 's/[ ]*:.*//;s/\[//;s/\]//;')
>
>     optsParam=$(echo "$helpOut" | grep arg$)
>     optsParam=$(echo $optsParam | sed -e 's/ arg//g;s/ /|/g')
>
>     # if not typing an option, or if the previous option required a
>     # parameter, then fallback on ordinary filename expansion
>     helpCmds='help|--help|h|\?'
>     if [[ ${COMP_WORDS[1]} != @($helpCmds) ]] && \
>        [[ "$cur" != -* ]] || \
>        [[ ${COMP_WORDS[COMP_CWORD-1]} == @($optsParam) ]] ; then
>     	return 0
>     fi
>
>     cmdOpts=$(echo $helpOut | sed -e 's/ arg//g')
>
>     COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )
>
>     return 0
> }
>
> _svn_new ()
> {
>     _svn_common "svn"
> }
> complete -F _svn_new -o default svn
>
> _svnadmin_new ()
> {
>     _svn_common "svnadmin"
> }

You have also removed the alternatives/exclusives handling, I'd like
to see that back.

My real problem is that I can't get it to work.  The things that don't
work are:

   $ svn <TAB>

The shell uses CPU and memory (it goes into swap) but doesn't generate
a list of commands.  Command completion fails in the same way:

   $ svn che<TAB>

but option expansion works fine:

   $ svn commit -<TAB><TAB>
   --config-dir       --message          --quiet            -m
   --editor-cmd       --no-auth-cache    --targets          -q
   --encoding         --non-interactive  --username         
   --file             --non-recursive    -F                 
   --force-log        --password         -N                 


-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org