Completando comandos de subversion en bash

El comando shopt permite establecer y ver las opciones de la bash:

casiano@exthost:~$ help shopt
shopt: shopt [-pqsu] [-o] [optname ...]
    Set and unset shell options.
    
    Change the setting of each shell option OPTNAME.  Without any option
    arguments, list all shell options with an indication of whether or not each
    is set.
    
    Options:
      -o    restrict OPTNAMEs to those defined for use with `set -o'
      -p    print each shell option with an indication of its status
      -q    suppress output
      -s    enable (set) each OPTNAME
      -u    disable (unset) each OPTNAME
    
    Exit Status:
    Returns success if OPTNAME is enabled; fails if an invalid option is
    given or OPTNAME is disabled.
Sin argumentos muestra los valores actuales de las opciones:
casiano@exthost:~$ shopt
autocd          off
cdable_vars     off
cdspell         off
checkhash       off
checkjobs       off
checkwinsize    on
cmdhist         on
compat31        off
compat32        off
dirspell        off
dotglob         off
execfail        off
expand_aliases  on
extdebug        off
extglob         on
extquote        on
failglob        off
force_fignore   on
globstar        off
gnu_errfmt      off
histappend      off
histreedit      off
histverify      off
hostcomplete    on
huponexit       off
interactive_comments    on
lithist         off
login_shell     on
mailwarn        off
no_empty_cmd_completion off
nocaseglob      off
nocasematch     off
nullglob        off
progcomp        on
promptvars      on
restricted_shell    off
shift_verbose   off
sourcepath      on
xpg_echo        off

Las opciones extglob y progcomp gobiernan la forma en la que se completan los comandos cuando se presiona la tecla TAB:

$shopt -s extglob progcomp
Por otro lado el comando complete permite especificar como se completa un comando:
complete: complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] \
                   [-W wordlist]  [-F function] [-C command] [-X filterpat] \
                   [-P prefix] [-S suffix] [name ...]
    Specify how arguments are to be completed by Readline.
    
    For each NAME, specify how arguments are to be completed.  If no options
    are supplied, existing completion specifications are printed in a way that
    allows them to be reused as input.
    
    Options:
      -p    print existing completion specifications in a reusable format
      -r    remove a completion specification for each NAME, or, if no
        NAMEs are supplied, all completion specifications
    
    When completion is attempted, the actions are applied in the order the
    uppercase-letter options are listed above.
    
    Exit Status:
    Returns success unless an invalid option is supplied or an error occurs.

Así, si hacemos:

complete -W 'add blame praise annotate cat checkout co cleanup commit ci copy delete del \
             remove rm diff di export help h import info list ls log merge mkdir move mv \
             rename ren propdel pdel pd propedit pedit pe propget pget pg proplist plist pl \
             propset pset ps resolved revert status stat st switch sw update up' svn

Un comando como svn h<TAB> se completrá a svn help.

Mejor aún, localize el fichero bash_completion que viene con la distribución de subversion. Puede encontrarlo en:

hágale un source a dicho script:

$ . bash_completion
Así podrá completar también las opciones de los subcomandos.

Casiano Rodríguez León
Licencia de Creative Commons
Principios de Programación Imperativa, Funcional y Orientada a Objetos Una Introducción en Perl/Una Introducción a Perl
por Casiano Rodríguez León is licensed under a Creative Commons Reconocimiento 3.0 Unported License.

Permissions beyond the scope of this license may be available at http://campusvirtual.ull.es/ocw/course/view.php?id=43.
2012-06-19