diff --git a/50-ollama-completion b/50-ollama-completion index 3641d22..10f9f51 100755 --- a/50-ollama-completion +++ b/50-ollama-completion @@ -7,18 +7,14 @@ command -v ollama &>/dev/null || return _ollama_models() { - # List locally available model names (NAME column, strip tag if ":latest") - ollama list 2>/dev/null | awk 'NR>1 {print $1}' + timeout 2 ollama list 2>/dev/null | awk 'NR>1 {print $1}' } _ollama_running_models() { - # List currently running model names - ollama ps 2>/dev/null | awk 'NR>1 {print $1}' + timeout 2 ollama ps 2>/dev/null | awk 'NR>1 {print $1}' } -_ollama_launch_integrations() { - printf '%s\n' claude cline codex droid opencode openclaw clawdbot moltbot pi -} +_OLLAMA_LAUNCH_INTEGRATIONS="claude cline codex droid opencode openclaw clawdbot moltbot pi" _ollama_completions() { local cur prev @@ -27,16 +23,10 @@ _ollama_completions() { 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" - # Subcommand-specific flags case "${prev}" in - run) - COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) - return 0 - ;; - show) + run|show|rm|cp|push|--model) COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) return 0 ;; @@ -44,31 +34,17 @@ _ollama_completions() { COMPREPLY=( $(compgen -W "$(_ollama_running_models)" -- "${cur}") ) return 0 ;; - rm) - COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) - return 0 - ;; - cp) - COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) - return 0 - ;; - push) - COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) - return 0 - ;; pull) - # No local completions useful for pull (user types a registry name) return 0 ;; launch) - COMPREPLY=( $(compgen -W "$(_ollama_launch_integrations)" -- "${cur}") ) + COMPREPLY=( $(compgen -W "${_OLLAMA_LAUNCH_INTEGRATIONS}" -- "${cur}") ) return 0 ;; help) COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") ) return 0 ;; - # Flag-specific value completions --format) COMPREPLY=( $(compgen -W "json" -- "${cur}") ) return 0 @@ -81,13 +57,8 @@ _ollama_completions() { COMPREPLY=( $(compgen -f -- "${cur}") ) return 0 ;; - --model) - COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) - return 0 - ;; esac - # Determine which subcommand we're in (if any) local subcmd="" local i for (( i=1; i < COMP_CWORD; i++ )); do @@ -99,7 +70,6 @@ _ollama_completions() { esac done - # Per-subcommand flag completion if [[ "${cur}" == -* ]]; then local sub_opts="" case "${subcmd}" in @@ -126,19 +96,18 @@ _ollama_completions() { return 0 fi - # Handle model-name completion for rm (supports multiple models) + # rm supports multiple model arguments if [[ "${subcmd}" == "rm" ]]; then COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) return 0 fi - # Handle second argument for cp (destination) + # cp destination (second argument) if [[ "${subcmd}" == "cp" && ${COMP_CWORD} -ge 3 ]]; then COMPREPLY=( $(compgen -W "$(_ollama_models)" -- "${cur}") ) return 0 fi - # Top-level: complete subcommands and global options if [[ ${COMP_CWORD} -eq 1 ]]; then COMPREPLY=( $(compgen -W "${commands} ${global_opts}" -- "${cur}") ) fi