Skip to content

Instantly share code, notes, and snippets.

@thomd
Last active March 18, 2025 08:19
Show Gist options
  • Save thomd/b007a85abb073b0b0fa740ae3687f3c2 to your computer and use it in GitHub Desktop.
Save thomd/b007a85abb073b0b0fa740ae3687f3c2 to your computer and use it in GitHub Desktop.
ollama(1) bash completion
#!/usr/bin/env bash
# SETUP
#
# copy into bash_completion.d
# brew install bash-completion@2
#
_complete_ollama() {
local cur prev words cword
_init_completion -n : || return
if [[ ${cword} -eq 1 ]]; then
COMPREPLY=($(compgen -W "serve create show run stop push pull list ps cp rm help" -- "${cur}"))
elif [[ ${cword} -eq 2 ]]; then
case "${prev}" in
(run|show|stop|cp|rm|push|list)
WORDLIST=$(ollama list 2>/dev/null | sed 1d | awk '{print $1}')
COMPREPLY=($(compgen -W "${WORDLIST}" -- "${cur}"))
__ltrim_colon_completions "$cur"
;;
esac
fi
}
complete -F _complete_ollama ollama
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment