Skip to content

Instantly share code, notes, and snippets.

@chiroptical
Last active October 21, 2020 21:09
Show Gist options
  • Save chiroptical/4014eb623938d166fa53ac279875300b to your computer and use it in GitHub Desktop.
Save chiroptical/4014eb623938d166fa53ac279875300b to your computer and use it in GitHub Desktop.
all_commands=(
run
run.file
run.pipe
transcript
version
help
-codebase
transcript.fork
)
commands_accepting_dir=(
-codebase
)
commands_accepting_file=(
-save-codebase
transcript.fork
run.file
)
transcript_only=(
-save-codebase
)
_unison_complete() {
local cur_word prev_word
cur_word="${COMP_WORDS[COMP_CWORD]}"
prev_word="${COMP_WORDS[COMP_CWORD-1]}"
if [[ ${prev_word} == "unison" ]]; then
COMPREPLY=($(compgen -W "$(echo ${all_commands[@]})" -- ${cur_word}))
elif [[ ${prev_word} == "transcript" ]]; then
COMPREPLY=($(compgen -W "$(echo ${transcript_only[@]})" -f -d -- ${cur_word}))
elif [[ "${commands_accepting_dir[@]}" =~ "${prev_word}" ]]; then
COMPREPLY=($(compgen -d -- ${cur_word}))
elif [[ "${commands_accepting_file[@]}" =~ "${prev_word}" ]]; then
COMPREPLY=($(compgen -f -- ${cur_word}))
fi
return 0
}
complete -o filenames -o nospace -o bashdefault -F _unison_complete unison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment