Skip to content

Instantly share code, notes, and snippets.

@raphink
Created April 26, 2012 06:39
Show Gist options
  • Save raphink/2496775 to your computer and use it in GitHub Desktop.
Save raphink/2496775 to your computer and use it in GitHub Desktop.
Simple bash completion for mcollective
_mco()
{
local cur cmd agents
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
cmd=${COMP_WORDS[0]}
if [ $COMP_CWORD -eq 1 ]; then
agents=$($cmd | sed -n "s@Known commands: @@p")
COMPREPLY=($(compgen -W "$agents" -- "$cur"))
elif [ $COMP_CWORD -eq 2 ]; then
options=$($cmd $prev --help | grep -o -- '-[^, ]\+')
COMPREPLY=($(compgen -W "$options" -- "$cur"))
fi
}
[ -n "${have:-}" ] && complete -F _mco mco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment