Skip to content

Instantly share code, notes, and snippets.

@mtholder
Created April 4, 2013 16:29
Show Gist options
  • Select an option

  • Save mtholder/5311880 to your computer and use it in GitHub Desktop.

Select an option

Save mtholder/5311880 to your computer and use it in GitHub Desktop.
bash tab completion for the treemachine command
_treemachine()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
if test $prev = "treemachine"
then
# if the previous word was treemachine, prompt with the commands
COMPREPLY=( $(compgen -W "addtree reprocess deletetrees jsgol fulltree fulltree_sources fulltreelist mrpdump graphml csvdump justtrees sourceexplorer listsources biparts mapsupport getlicanames counttips diversity labeltips getupdatedlist" -- $cur))
else
#otherwise do file completion. Which seems tougher than it should be...
COMPREPLY=()
if test "${cur:0:1}" = '$'
then
if test $(expr match "${cur}" ".*/.*") -eq 0
then
# arg starts with env var and does not have a /
COMPREPLY=( $(compgen -P \$ -e "${cur:1}") )
else
# arg starts with an env var and has path separators
COMPREPLY=( $(compgen -o default "${cur}") )
fi
else
# arg does not start with a env var. Do normal file completion
COMPREPLY=( $(compgen -f "${cur}") )
fi
if test "$COMPREPLY" = "${cur}" -a -d "${cur}" -a "${cur:(-1)}" != "/"
then
#arg is a dir, add the / and expand on that
COMPREPLY=( $(compgen -f "${cur}/") )
fi
return 0
fi
}
complete -F _treemachine treemachine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment