diff options
| author | gongysh <gongysh@cn.ibm.com> | 2012-10-08 18:48:26 +0800 |
|---|---|---|
| committer | gongysh <gongysh@cn.ibm.com> | 2012-10-08 18:48:26 +0800 |
| commit | c8e7ed26befb9a413e5b6dee8a5e9e4db28a17c5 (patch) | |
| tree | 5828c64235d077c62f3cf7e71c0f6f5f1b3a5195 /tools | |
| parent | 3e19fc0a563e78ff81c63788e6f3d163054ff34f (diff) | |
| download | python-neutronclient-c8e7ed26befb9a413e5b6dee8a5e9e4db28a17c5.tar.gz | |
Generate bash_completion string so that we can use bash completion.
Bug #1063500
To install, copy tools/quantum.bash_completion to
/etc/bash_completion.d/quantum
Change-Id: I0afff3967c63111854455226fc90092f5bc7845a
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/quantum.bash_completion | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/quantum.bash_completion b/tools/quantum.bash_completion new file mode 100644 index 0000000..45db025 --- /dev/null +++ b/tools/quantum.bash_completion @@ -0,0 +1,27 @@ +_quantum_opts="" # lazy init +_quantum_flags="" # lazy init +_quantum_opts_exp="" # lazy init +_quantum() +{ + local cur prev nbc cflags + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + if [ "x$_quantum_opts" == "x" ] ; then + nbc="`quantum bash-completion | sed -e "s/\s-h\s/\s/"`" + _quantum_opts="`echo "$nbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/\s\s*/ /g"`" + _quantum_flags="`echo " $nbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/\s\s*/ /g"`" + _quantum_opts_exp="`echo "$_quantum_opts" | sed -e "s/\s/|/g"`" + fi + + if [[ " ${COMP_WORDS[@]} " =~ " "($_quantum_opts_exp)" " && "$prev" != "help" ]] ; then + COMPLETION_CACHE=~/.quantumclient/*/*-cache + cflags="$_quantum_flags "$(cat $COMPLETION_CACHE 2> /dev/null | tr '\n' ' ') + COMPREPLY=($(compgen -W "${cflags}" -- ${cur})) + else + COMPREPLY=($(compgen -W "${_quantum_opts}" -- ${cur})) + fi + return 0 +} +complete -F _quantum quantum |
