_llama_completions() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    opts="-h --help --usage --version --license -cl --cache-list --completion-bash --verbose-prompt -t --threads -tb --threads-batch -C --cpu-mask -Cr --cpu-range --cpu-strict --prio --poll -Cb --cpu-mask-batch -Crb --cpu-range-batch --cpu-strict-batch --prio-batch --poll-batch -c --ctx-size -n --predict --n-predict -b --batch-size -ub --ubatch-size --keep --swa-full -fa --flash-attn --perf -e --escape --rope-scaling --rope-scale --rope-freq-base --rope-freq-scale --yarn-orig-ctx --yarn-ext-factor --yarn-attn-factor --yarn-beta-slow --yarn-beta-fast -kvo --kv-offload --repack --no-host -ctk --cache-type-k -ctv --cache-type-v -dt --defrag-thold --rpc --mlock --mmap -dio --direct-io --numa -dev --device --list-devices -ot --override-tensor -cmoe --cpu-moe -ncmoe --n-cpu-moe -ngl --gpu-layers --n-gpu-layers -sm --split-mode -ts --tensor-split -mg --main-gpu -fit --fit -fitt --fit-target -fitc --fit-ctx --check-tensors --override-kv --op-offload --lora --lora-scaled --control-vector --control-vector-scaled --control-vector-layer-range -m --model -mu --model-url -dr --docker-repo -hf -hfr --hf-repo -hfd -hfrd --hf-repo-draft -hff --hf-file -hfv -hfrv --hf-repo-v -hffv --hf-file-v -hft --hf-token --log-disable --log-file --log-colors -v --verbose --log-verbose --offline -lv --verbosity --log-verbosity --log-prefix --log-timestamps -ctkd --cache-type-k-draft -ctvd --cache-type-v-draft --samplers -s --seed --sampler-seq --sampling-seq --ignore-eos --temp --temperature --top-k --top-p --min-p --top-nsigma --top-n-sigma --xtc-probability --xtc-threshold --typical --typical-p --repeat-last-n --repeat-penalty --presence-penalty --frequency-penalty --dry-multiplier --dry-base --dry-allowed-length --dry-penalty-last-n --dry-sequence-breaker --adaptive-target --adaptive-decay --dynatemp-range --dynatemp-exp --mirostat --mirostat-lr --mirostat-ent -l --logit-bias --grammar --grammar-file -j --json-schema -jf --json-schema-file -bs --backend-sampling -lcs --lookup-cache-static -lcd --lookup-cache-dynamic --ctx-checkpoints --swa-checkpoints -cram --cache-ram -kvu --kv-unified --context-shift -r --reverse-prompt -sp --special --warmup --spm-infill --pooling -np --parallel -cb --cont-batching -mm --mmproj -mmu --mmproj-url --mmproj-auto --mmproj-offload --image-min-tokens --image-max-tokens -otd --override-tensor-draft -cmoed --cpu-moe-draft -ncmoed --n-cpu-moe-draft -a --alias --tags --host --port --path --api-prefix --webui-config --webui-config-file --webui --embedding --embeddings --rerank --reranking --api-key --api-key-file --ssl-key-file --ssl-cert-file --chat-template-kwargs -to --timeout --threads-http --cache-prompt --cache-reuse --metrics --props --slots --slot-save-path --media-path --models-dir --models-preset --models-max --models-autoload --jinja --reasoning-format --reasoning-budget --chat-template --chat-template-file --prefill-assistant -sps --slot-prompt-similarity --lora-init-without-apply --sleep-idle-seconds -td --threads-draft -tbd --threads-batch-draft --draft --draft-n --draft-max --draft-min --draft-n-min --draft-p-min -cd --ctx-size-draft -devd --device-draft -ngld --gpu-layers-draft --n-gpu-layers-draft -md --model-draft --spec-replace --spec-type --spec-ngram-size-n --spec-ngram-size-m --spec-ngram-min-hits -mv --model-vocoder --tts-use-guide-tokens --embd-gemma-default --fim-qwen-1.5b-default --fim-qwen-3b-default --fim-qwen-7b-default --fim-qwen-7b-spec --fim-qwen-14b-spec --fim-qwen-30b-default --gpt-oss-20b-default --gpt-oss-120b-default --vision-gemma-4b-default --vision-gemma-12b-default "

    case "$prev" in
        --model|-m)
            COMPREPLY=( $(compgen -f -X '!*.gguf' -- "$cur") $(compgen -d -- "$cur") )
            return 0
            ;;
        --grammar-file)
            COMPREPLY=( $(compgen -f -X '!*.gbnf' -- "$cur") $(compgen -d -- "$cur") )
            return 0
            ;;
        --chat-template-file)
            COMPREPLY=( $(compgen -f -X '!*.jinja' -- "$cur") $(compgen -d -- "$cur") )
            return 0
            ;;
        *)
            COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
            return 0
            ;;
    esac
}

complete -F _llama_completions llama-batched
complete -F _llama_completions llama-batched-bench
complete -F _llama_completions llama-bench
complete -F _llama_completions llama-cli
complete -F _llama_completions llama-completion
complete -F _llama_completions llama-convert-llama2c-to-ggml
complete -F _llama_completions llama-cvector-generator
complete -F _llama_completions llama-embedding
complete -F _llama_completions llama-eval-callback
complete -F _llama_completions llama-export-lora
complete -F _llama_completions llama-gen-docs
complete -F _llama_completions llama-gguf
complete -F _llama_completions llama-gguf-hash
complete -F _llama_completions llama-gguf-split
complete -F _llama_completions llama-gritlm
complete -F _llama_completions llama-imatrix
complete -F _llama_completions llama-infill
complete -F _llama_completions llama-llava-clip-quantize-cli
complete -F _llama_completions llama-lookahead
complete -F _llama_completions llama-lookup
complete -F _llama_completions llama-lookup-create
complete -F _llama_completions llama-lookup-merge
complete -F _llama_completions llama-lookup-stats
complete -F _llama_completions llama-mtmd-cli
complete -F _llama_completions llama-parallel
complete -F _llama_completions llama-passkey
complete -F _llama_completions llama-perplexity
complete -F _llama_completions llama-q8dot
complete -F _llama_completions llama-quantize
complete -F _llama_completions llama-qwen2vl-cli
complete -F _llama_completions llama-retrieval
complete -F _llama_completions llama-save-load-state
complete -F _llama_completions llama-server
complete -F _llama_completions llama-simple
complete -F _llama_completions llama-simple-chat
complete -F _llama_completions llama-speculative
complete -F _llama_completions llama-speculative-simple
complete -F _llama_completions llama-tokenize
complete -F _llama_completions llama-tts
complete -F _llama_completions llama-vdot
