A ruby a day!

rpa Programmable Completion

rpa programmable completion at work

If you use bash, you can make rpa more intelligent.

You can enable programmable completion for rpa by sourcing in the following file:

# Debian GNU/Linux rpa completion
# Made for "rpa (rpa-base 0.2.2-6) RPA 0.0"
# Copyright 2004 Brian Schröder 
# See http://ruby.brian-amberg.de/ for the latest version.
# License: GNU LGPL v2 or later

_rpa() {
    local cur prev cmd idx

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}

    RPA_SIMPLE_COMMANDS=(list update rollback clean help dist-upgrade)
    RPA_LOCAL_PORT_COMMANDS=(remove info check)
    RPA_REMOTE_PORT_COMMANDS=(install build source query search)
    RPA_PORT_COMMANDS=(${RPA_LOCAL_PORT_COMMANDS[*]} ${RPA_REMOTE_PORT_COMMANDS[*]})
    RPA_OPTIONS=(-h --help --no-proxy --proxy -q --quiet -x --extended \
                 --verbose --debug -v --version \
                 -f --force -p --parallelize --no-tests -r --requires \
                 -c --classification -e -eval -D --eval-display)

    idx=1
    while [ $idx -lt $COMP_CWORD ]; do
        case "${COMP_WORDS[idx]}" in
        -*) ;;
        *) prev="${COMP_WORDS[idx]}"; break;;
        esac
        idx=$[idx+1]
    done
    if [ ${prev+set} ]; then
        case " ${RPA_SIMPLE_COMMANDS[*]} " in
        *" $prev "*)
            COMPREPLY=( $(compgen -W "${RPA_OPTIONS[*]}" ${cur}) );
            return 0;;
        esac
        case " ${RPA_LOCAL_PORT_COMMANDS[*]} " in
        *" $prev "*)
            cmd=list;;
        esac
        case " ${RPA_REMOTE_PORT_COMMANDS[*]} " in
        *" $prev "*)
            cmd=query;;
        esac
        if [ "$cmd" ]; then
            COMPREPLY=( $(compgen -W "$(rpa $cmd | ruby -n -e 'puts $1 if /([-\w]+)\s+[0-9]+/')" ${cur} ) )
        else
            COMPREPLY=( $(compgen -W "${RPA_SIMPLE_COMMANDS[*]} ${RPA_PORT_COMMANDS[*]} ${RPA_OPTIONS[*]}" ${cur} ) )
        fi
    fi

    return 0
}
complete -F _rpa rpa

# 10/11/2004: First release
# 10/12/2004: Patch by Mauricio Fernández
#             - Get list of remote packages
# 10/19/2004: Patch/Rewrite by Nobu Nokada
#             - Lots of improvements
# 12/08/2004: Patch by Brian Schröder
#             - Include dist-update command

Under Debian the easiest way to achieve this is putting the source above into a file /etc/bash_completion.d/rpa

You may download this file here rpa completion.

Good luck,

Brian

Versions