add bash completion script

This patch add a script rally.bash_completion which enables
auto-completion of rally CLI in bash environmnet when running:

python setup.py install
or
python setup.py develop

test:
rally [tab]
rally ta[tab]
rally task [tab]
rally task de[tab]

to-do:
adding a cache to bash-completion result could speed up auto-completion

Change-Id: Ia4c68ccf3faea73da87a93ce64b36545d9d8411c
This commit is contained in:
Kun Huang 2014-06-13 00:42:27 +08:00 committed by Sergey Skripnick
parent 2c5ced4ea4
commit 7ef742af1b
2 changed files with 19 additions and 0 deletions

View File

@ -27,4 +27,5 @@ except ImportError:
setuptools.setup(
setup_requires=['pbr'],
data_files=[('/etc/bash_completion.d', ['tools/rally.bash_completion'])],
pbr=True)

View File

@ -0,0 +1,18 @@
_rally_opts="" # lazy init
_rally_flags="" # lazy init
_rally_opts_exp="" # lazy init
_rally()
{
local cur prev rbc cflags
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
base_opts="`rally bash-completion`"
if [ $prev == "rally" ] && [ $COMP_CWORD == "1" ] ; then
COMPREPLY=($(compgen -W "${base_opts}" -- ${cur}))
else
COMPREPLY=($(compgen -W "`rally bash-completion $prev `" -- ${cur}))
fi
return 0
}
complete -F _rally rally