[ditz-talk] bash completion
mitch at cgarbs.de
Tue Jul 22 09:40:02 EDT 2008
On Mon, Jul 21, 2008 at 05:52:38PM -0700, William Morgan wrote:
> Ok, check out the master branch. You should be able to call it with
> "<options>" at any argument position to get the list of possible
> E.g. "ditz assign <options>" prints the list of all issues, and "ditz
> assign ditz-5 <options>" prints the list of all releases.
This works great!
The relevant part for the bash completion is this:
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $( compgen -W "$(ditz --commands)" $cur ) )
elif [ $COMP_CWORD -eq 2 ]; then
COMPREPLY=( $( compgen -W "$(ditz "$cmd" '<options>' 2>/dev/null)" $cur ) )
elif [ $COMP_CWORD -eq 3 ]; then
COMPREPLY=( $( compgen -W "$(ditz "$cmd" "$parm1" '<options>' 2>/dev/null)" $cur ) )
Currently the if..elif..fi needs to be expanded if there would be a
command with three arguments. You could propably refactor it to use a
list but this way it's easier to understand.
I've noticed that only mandatory arguments are expanded. It would be
nice to expand optional arguments, too, eg. 'ditz help <options>'
giving a list of all commands.
ditz add-release [name]
ditz assign <issue> [release]
ditz help [command]
ditz set-component <issue> [component]
ditz status [release]
ditz todo [release]
ditz todo-full [release]
This does not need to be done for [dir] arguments (like in ditz
archive or ditz html) as filename/directory expansion is the default
expansion mechanism of the shell.
The Consultant's Curse:
When the customer has beaten upon you long enough, give him
what he asks for, instead of what he needs. This is very strong
medicine, and is normally only required once.
More information about the ditz-talk