2026-03-29 19:46:55 +02:00
|
|
|
# shellcheck shell=bash
|
|
|
|
|
# shellcheck disable=SC2207 # Standard pattern for bash completions
|
|
|
|
|
# Bash completion for Ollama CLI
|
|
|
|
|
# Hand-written because ollama does not yet expose a "completion" subcommand.
|
|
|
|
|
# TODO: Replace with cached_completion once "ollama completion bash" is available.
|
|
|
|
|
|
|
|
|
|
command -v ollama &>/dev/null || return
|
|
|
|
|
|
|
|
|
|
_ollama_models() {
|
2026-03-29 19:56:51 +02:00
|
|
|
timeout 2 ollama list 2>/dev/null | awk 'NR>1 {print $1}'
|
2026-03-29 19:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ollama_running_models() {
|
2026-03-29 19:56:51 +02:00
|
|
|
timeout 2 ollama ps 2>/dev/null | awk 'NR>1 {print $1}'
|
2026-03-29 19:46:55 +02:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 19:56:51 +02:00
|
|
|
_OLLAMA_LAUNCH_INTEGRATIONS="claude cline codex droid opencode openclaw clawdbot moltbot pi"
|
2026-03-29 19:46:55 +02:00
|
|
|
|
|
|
|
|
_ollama_completions() {
|
|
|
|
|
local cur prev
|
|
|
|
|
COMPREPLY=()
|
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
|
|
|
|
|
|
local commands="serve create show run stop pull push signin signout list ls ps cp rm launch help"
|
|
|
|
|
local global_opts="--help --nowordwrap --verbose --version"
|
|
|
|
|
|
|
|
|
|
case "${prev}" in
|
2026-03-29 19:56:51 +02:00
|
|
|
run|show|rm|cp|push|--model)
|
2026-03-29 19:46:55 +02:00
|
|
|
COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
stop)
|
|
|
|
|
COMPREPLY=( $(compgen -W "$(_ollama_running_models)" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
pull)
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
launch)
|
2026-03-29 19:56:51 +02:00
|
|
|
COMPREPLY=( $(compgen -W "${_OLLAMA_LAUNCH_INTEGRATIONS}" -- "${cur}") )
|
2026-03-29 19:46:55 +02:00
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
help)
|
|
|
|
|
COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
--format)
|
|
|
|
|
COMPREPLY=( $(compgen -W "json" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
--quantize|-q)
|
|
|
|
|
COMPREPLY=( $(compgen -W "q4_0 q4_1 q4_K_S q4_K_M q5_0 q5_1 q5_K_S q5_K_M q8_0" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
--file|-f)
|
|
|
|
|
COMPREPLY=( $(compgen -f -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
local subcmd=""
|
|
|
|
|
local i
|
|
|
|
|
for (( i=1; i < COMP_CWORD; i++ )); do
|
|
|
|
|
case "${COMP_WORDS[i]}" in
|
|
|
|
|
run|show|stop|pull|push|cp|rm|create|serve|list|ls|ps|launch|signin|signout|help)
|
|
|
|
|
subcmd="${COMP_WORDS[i]}"
|
|
|
|
|
break
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [[ "${cur}" == -* ]]; then
|
|
|
|
|
local sub_opts=""
|
|
|
|
|
case "${subcmd}" in
|
|
|
|
|
run)
|
|
|
|
|
sub_opts="--format --insecure --keepalive --nowordwrap --verbose
|
|
|
|
|
--hidethinking --think --experimental --experimental-websearch
|
|
|
|
|
--experimental-yolo --dimensions --truncate
|
|
|
|
|
--width --height --steps --seed --negative"
|
|
|
|
|
;;
|
|
|
|
|
show)
|
|
|
|
|
sub_opts="--license --modelfile --parameters --system --template --verbose"
|
|
|
|
|
;;
|
|
|
|
|
pull|push)
|
|
|
|
|
sub_opts="--insecure"
|
|
|
|
|
;;
|
|
|
|
|
create)
|
|
|
|
|
sub_opts="--file --quantize --experimental"
|
|
|
|
|
;;
|
|
|
|
|
launch)
|
|
|
|
|
sub_opts="--config --model --yes"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
COMPREPLY=( $(compgen -W "${sub_opts} --help" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-29 19:56:51 +02:00
|
|
|
# rm supports multiple model arguments
|
2026-03-29 19:46:55 +02:00
|
|
|
if [[ "${subcmd}" == "rm" ]]; then
|
|
|
|
|
COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-03-29 19:56:51 +02:00
|
|
|
# cp destination (second argument)
|
2026-03-29 19:46:55 +02:00
|
|
|
if [[ "${subcmd}" == "cp" && ${COMP_CWORD} -ge 3 ]]; then
|
|
|
|
|
COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") )
|
|
|
|
|
return 0
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ ${COMP_CWORD} -eq 1 ]]; then
|
|
|
|
|
COMPREPLY=( $(compgen -W "${commands} ${global_opts}" -- "${cur}") )
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
complete -F _ollama_completions ollama
|