Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Feature request: a bash completion script that extends nova bash completion and lets you tab complete your environment names #21

Open
dwcramer opened this issue Jun 20, 2013 · 2 comments

Comments

@dwcramer
Copy link

python-novaclient has a bash completion script that I can modify to use with supernova:

https://github.com/openstack/python-novaclient/blob/master/tools/nova.bash_completion

It would be cool if supernova provided that AND added the environment names from the ~/.supernova file to the completion cache.

@dwcramer
Copy link
Author

Here's my version. I've adapted it from nova.bash_completion by changing the function name and command from nova to supernova and adding line 24 and adjusting line 25 to append the sections from ~/.supernova to _nova_opts: i.e. " grep "[.*]" ~/.supernova | sed "s/[//" | sed "s/]//" > ~/.novaclient/environments" and "_nova_opts="$_nova_opts "$(cat ~/.novaclient/environments 2> /dev/null | tr '\n' ' ')"

_nova_opts="" # lazy init
_nova_flags="" # lazy init
_nova_opts_exp="" # lazy init
_supernova()
{
local cur prev nbc cflags
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"

if [ "x$_nova_opts" == "x" ] ; then
    nbc="`nova bash-completion | sed -e "s/[ ]+/ /"`"
    _nova_opts="`echo "$nbc" | sed -e "s/--[a-z0-9_-]*//g" -e "s/[ ]+/ /g"`"
    _nova_flags="`echo " $nbc" | sed -e "s/ [^-][^-][a-z0-9_-]*//g" -e "s/[ ]+/ /g"`"
    _nova_opts_exp="`echo "$_nova_opts" | sed -e "s/[ ]/|/g"`"
fi

if [[ " ${COMP_WORDS[@]} " =~ " "($_nova_opts_exp)" " && "$prev" != "help" ]] ; then
    COMPLETION_CACHE=~/.novaclient/*/*-cache
    cflags="$_nova_flags "$(cat $COMPLETION_CACHE 2> /dev/null | tr '\n' ' ')
    COMPREPLY=($(compgen -W "${cflags}" -- ${cur}))
else
    grep "\[.*\]" ~/.supernova | sed "s/\[//" | sed "s/\]//" > ~/.novaclient/environments
    _nova_opts="$_nova_opts "$(cat ~/.novaclient/environments 2> /dev/null | tr '\n' ' ')
    COMPREPLY=($(compgen -W "${_nova_opts}" -- ${cur}))
fi
return 0
}
complete -F _supernova supernova

@msabramo
Copy link
Contributor

msabramo commented Jul 8, 2016

Since supernova uses the click module, you can also uses click's automatic bash completion generation, but I think that only works for options and not for environments.

$ eval "$(_SUPERNOVA_COMPLETE=source supernova)"

Then I can do:

$ supernova --<Tab>
--conf        --dashboard   --debug       --echo        --executable  --list        --quiet       --shortlist   --version

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants