Skip to content

Instantly share code, notes, and snippets.

@kwilczynski
Created April 14, 2011 01:12
Show Gist options
  • Save kwilczynski/918742 to your computer and use it in GitHub Desktop.
Save kwilczynski/918742 to your computer and use it in GitHub Desktop.
Very simple bash completion for mco from MCollective
_mco()
{
local binary commands current previous
binary=$(which mco 2> /dev/null)
if [[ -x "${binary}" ]] ; then
COMPREPLY=()
current=${COMP_WORDS[COMP_CWORD]}
current=${current//\\\\/}
previous=${COMP_WORDS[COMP_CWORD - 1]}
commands=$( "${binary}" | \
grep -i 'commands' | cut -d ':' -f 2 | sed 's/^[ \t]*//;s/[ \t]*$//' )
if [[ ${COMP_CWORD} == 1 ]] && [[ "${current}" != -* ]] ; then
COMPREPLY=( $(compgen -W "${commands}" -- "${current}") )
elif [[ ${COMP_CWORD} > 1 ]] && [[ "${current}" == -* ]] ; then
COMPREPLY=( $(compgen -W '-1 -A -c -C -F -h -I -q -t -T -v -W \
--dt --ln --np --wa --wc --wf --wi --config --help --one \
--quiet --target --timeout --verbose --with --discovery-timeout \
--limit-nodes --no-progress --with-agent --with-class --with-fact \
--with-identity' -- "${current}") )
else
COMPREPLY=( $(compgen -f -- "${current}") )
fi
fi
return 0
}
complete -F _mco mco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment