Enable bash completion of commands and projects for https://github.com/jonathantneal/ok
# Bash completion of commands and projects for https://github.com/jonathantneal/ok
__ok_completion() {
local commands projects
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands="$(find $HOME/.ok/command -name '*.sh' -exec basename {} .sh \;)"
projects="$(find $HOME/.ok/project -name '*.sh' -not -name 'ok.sh' -exec basename {} .sh \;)"
if [[ ${prev} == "ok" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
return 0
else
COMPREPLY=( $(compgen -W "${projects}" -- ${cur}) )
return 0
fi
}
complete -o bashdefault -F __ok_completion ok