adaszko / complgen

Declarative bash/fish/zsh completions without writing shell scripts
Apache License 2.0
221 stars 7 forks source link

Provide instructions on how to integrate JIT completions with {bash,fish,zsh} #10

Closed adaszko closed 1 year ago

adaszko commented 1 year ago
_complgen_jit () {
    local command=$1
    local -a w=("${(@)words[2,$#words]}")
    local -a completions=($(complgen complete ~/.config/complgen/${command}.usage $((CURRENT - 2)) -- "${w[@]}"))
    compadd -a completions
    return 0
}

for f in $HOME/.config/complgen/*.usage; do
    local stem=$f:t:r
    compdef "_complgen_jit $stem" $stem
done