much improved zsh completion script

Steve Borho steve at ageia.com
Wed Oct 19 21:05:05 BST 2005


ZSH fans enjoy:

Attached is a version of the _bzr zsh completion script which has been largely 
completed.

I'm CC:ing this directly to Martin because my last post to the mailing list 
was stuck indefinitely in the moderator queue.

Two things I found while implementing these completion functions:

1) The documentation for merge seems to be out-of-date.  the --merge-type 
argument is no longer supported, but is still listed in the help.

2) Optimally, bzr would make it easy to get lists of files in the context of 
the current directory.  For instance, if you were working four subdirs deep 
from the branch root, you would like to be able to type 'bzr add <TAB>' and 
have zsh complete a list of unknown files in the current directory.  

I couldn't figure out how to make this work with the current commands, so the 
bzr add and bzr commit completion functions only work properly from the 
repository root.

--
Steve

PS: I could have sent this as a patch, but the actual file was smaller.
-------------- next part --------------
#compdef bzr

# Rudimentary zsh completion support for bzr.

# -S means there are no options after a -- and that argument is ignored

# To use this you must arrange for it to be in a directory that is on
# your $fpath, and also for compinit to be run.  I don't understand
# how to get zsh to reload this file when it changes, other than by
# starting a new zsh.

local _bzr_subcommands expl curcontext="$curcontext" state line
local fileList
typeset -A opt_args

if [[ $service == "bzr" ]]; then
    _arguments -C -A "-*" \
    '*::command:->subcmd' && return 0

    if (( CURRENT == 1 )); then
      _bzr_subcommands=(${(f)"$(_call_program bzr bzr shell-complete)"})
      _describe -t subcommand 'subcommand' _bzr_subcommands
      return
    fi

    service="$words[1]"
    curcontext="${curcontext%:*}=$service:"
fi

case $service in
    (add)
       # Most people probably don't want the list of ignored files
       # fileList=( $(bzr unknowns) $(bzr ignored | cut -f 1 -d" ") )
       fileList=( $(bzr unknowns) )
       _arguments \
       '--no-recurse[do not recurse into subdirectories]' \
       '(-q)--quiet' \
       '(--quiet)-q' \
       '*:unknown files:( $fileList )'
    ;;

    (annotate|praise|blame)
        _arguments '*:files:_files'
    ;;

    (clone|branch|get)
        if (( CURRENT == 2 )); then
            _arguments \
            '(-r)--revision:rev:' \
            '(--revision)-r:rev:' \
            '--basis[specify basis branch]:basis:' \
            '*:FROM_LOCATION:_files -/'
        elif (( CURRENT == 3 )); then
            _arguments \
            '(-r)--revision:rev:' \
            '(--revision)-r:rev:' \
            '--basis[specify basis branch]:basis:' \
            '*:TO_LOCATION:_files -/'
        fi
    ;;

    (rename|mv)
        if (( CURRENT == 2 )); then
            _arguments '*:old name:_files'
        else
            _arguments '*:new name:'
        fi
    ;;

    (cat)
        _arguments \
        '(-r)--revision:rev:' \
        '(--revision)-r:rev:' \
        '*:file:_files'
    ;;

    (root)
        _arguments '*:file:_files'
    ;;

    (log)
        _arguments \
        '(-r)--revision[revision or range]:rev or rev range:' \
        '(--revision)-r[revision or range]:rev or rev range:' \
        '(--verbose)-v[show revision manifest]' \
        '(-v)--verbose[show revision manifest]' \
        '(--short --long)-l[use long format (default)]' \
        '(--short -l)--long[use long format (default)]' \
        '(-l --long)--short[use short format]' \
        '(--message)-m[specify regexp]:regexp:' \
        '(-m)--message[specify regexp]:regexp:' \
        '--show-ids[show file IDs]' \
        '--forward[reverse direction of revisions]' \
        '--timezoe[specify timezone for dates]:timezone:' \
        '*:file:_files'
    ;;

    (resolve)
        _arguments '--all' '*:file:_files'
    ;;

    (status|st|stat)
        _arguments \
        '--all[include unchanged versioned files]' \
        '--show-ids[show file IDs]' \
        '*:file:_files'
    ;;

    (check)
        _arguments \
        '(--verbose)-v' \
        '(-v)--verbose' \
        '*:DIR:_files -/'
    ;;

    (mkdir|upgrade|renames)
        _arguments '*:DIR:_files -/'
    ;;

    (visualize|visualise|viz|vis)
        _arguments \
            '(-r)--revision[starting revision]:rev:' \
            '(--revision)-r[starting revision]:rev:'
    ;;

    (remove|rm)
        _arguments \
        '(--verbose)-v' \
        '(-v)--verbose' \
        '*:file:_files'
    ;;

    (pull)
        _arguments '--remember' '*:location:_files -/'
    ;;

    (missing|miss|mis)
        _arguments \
        '(--verbose -q --quiet)-v'
        '(-v -q --quiet)--verbose'
        '(--verbose -v --quiet)-q'
        '(-v -q --verbose)--quiet'
        '*:REMOTE:_files -/'
    ;;

    (commit|checkin|ci)
        fileList=( $(bzr modified) $(bzr added) $(bzr deleted))
        _arguments \
        '(--message)-m[commit message]:message text:' \
        '(-m)--message[commit message]:message text:' \
        '(--file)-F[commit message from file]:message file:' \
        '(-F)--file[commit message from file]:message file:' \
        '--unchanged[include unchanged files]' \
        '(--verbose)-v' \
        '(-v)--verbose' \
        '*:file:->modified'
        _wanted files expl 'mofified files' compadd -a fileList
    ;;

    (conflicts|added|deleted|modified|unknowns|directories|ignored)
    ;;

    (revno|init|version)
    ;;

    (whoami)
        _arguments '--email' 
    ;;

    (inventory)
        _arguments \
        '(-r)--revision[show inventory of a revision]:revision:' \
        '(--revision)-r[show inventory of a revision]:revision:' \
        '--show-ids[show file IDs]'
    ;;

    (diff|dif|di)
        _arguments \
        '(-r)--revision:revision:' \
        '(--revision)-r:revision:' \
        '--diff-options[options to pass to gdiff]:diff options:' \
        '*:files:_files'
    ;;

    (export)
        _arguments \
        '(-r)--revision:revision:' \
        '(--revision)-r:revision:' \
        '--format=[format of exported file]:format:(dir tar tgz tbz2)' \
        '--root[root directory of patch]:_files -/' \
        '*:destination:_files'
    ;;

    (ignore)
        _arguments '*:NAME_PATTERN:'
    ;;

    (info)
        _arguments '*:branch:_files -/'
    ;;

    (testament)
        _arguments \
        '(-r)--revision:revision:' \
        '(--revision)-r:revision:' \
        '(--long)-l' \
        '(-l)--long' \
        '*:branch:_files -/'
    ;;

    (revert|merge-revert)
        _arguments \
        '(-r)--revision:revision:' \
        '(--revision)-r:revision:' \
        '--no-backup[skip generation of backup~ files]' \
        '*:file:_files'
    ;;

    (merge)
        _arguments \
        '*(-r)--revision:revision:' \
        '*(--revision)-r:revision:' \
        '--force[ignore uncommitted changes]' \
        '*:branch:_files -/'

        # merge type doesn't seem to be supported anymore
        # '--merge-type:merge type:(diff3 what else?)' \
    ;;

    (move)
        if (( CURRENT == 2 )); then
            _arguments '*:files:_files'
        else
            _arguments '*:destination dir:_files -/'
        fi
    ;;

    (help)
        _bzr_subcommands=(${(f)"$(_call_program bzr bzr shell-complete)"})
        _arguments \
        '(--long)-l' \
        '(-l)--long' \
        '*:subcmds:->cmds'
        _describe -t subcommand 'subcommand' _bzr_subcommands
    ;;


    (*)
        _message "unknown bzr command completion: $service"
    ;;
esac


More information about the bazaar mailing list