Last active
March 18, 2025 08:19
-
-
Save thomd/b007a85abb073b0b0fa740ae3687f3c2 to your computer and use it in GitHub Desktop.
ollama(1) bash completion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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