Skip to content

Instantly share code, notes, and snippets.

@kennyp
Created July 1, 2013 17:00
Show Gist options
  • Save kennyp/5902608 to your computer and use it in GitHub Desktop.
Save kennyp/5902608 to your computer and use it in GitHub Desktop.
Auto-complete for hcl.
_hcl () {
local cur prev opts cmds tasks
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --version"
cmds="show tasks aliases set unset start stop resume note"
if [[ ${cur} == -* ]] ; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
elif [[ ${prev} == hcl ]] ; then
COMPREPLY=($(compgen -W "${cmds}" -- ${cur}))
return 0
elif [[ ${prev} == start ]] ; then
tasks=$(cat ~/.hcl_settings | grep ^task. | cut -d. -f2 | cut -d: -f1 | tr '\n' ' ')
COMPREPLY=($(compgen -W "${tasks}" -- ${cur}))
return 0
fi
}
complete -F _hcl hcl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment