ZSH Completions How To
github.com
github.com
You can implement a simple one without much effort. But doing anything a bit more interesting need to dig into zle, and there is only a few resources available online.
You can write completions declaratively and use TypeScript to generate dynamic suggestions.
Disclosure: I'm one of the founders.
I've though about using tree-sitter DSL to generate zsh completion.
Your project seems to be a better candidate for this. Tree-sitter DSL, with some extra annotations, could be used to generate the specification. With the added bonus of being a format that can provide syntax highlight on text editors (in commands in sh files).
If I not mistaken, tree-sitter also uses TS.
I only gave a quick look at fig (only use HN on mobile). Will have a better look when at the desktop.
I've declared a function `k` which tests if I'm currently on a `kubie` [0] shell. If it isn't, it runs `kubie ctx`; if it is, it runs `kubectl $@`.
I never write kubectl directly but rather run this `k` function. This way I'm always in the context I want and don't get surprises since I'm forgetful.
I'd like for this function to complete like it was kubectl itself.
So far I've tried:
compdef k=kubectl
compdef _kubectl k
compdef '_bash_complete -o default -F __start_kubectl' k
The last one is from the below, although I don't really understand what it's doing: $ grep kubectl ~/.zcompdump
'kubectl' '_bash_complete -o default -F __start_kubectl'
autoload -Uz _bat _brew _git _j _kubectl \
[0] https://github.com/sbstp/kubieWithout color, and trying to get NSH working with autocomplete (with bash autocomplete) it still didn’t work in NSH. I if it wasn’t for fish I’d still be using GUI, and if it was this and bash, I would have never felt comfortable configurating stuff I didn’t understand.
(it's a simple example that doesn't add a lot of usefulness, but there is other usecase like the -n of kubectl, it is very useful to have the completion of kubectl namespaces in there after -n)
For fuzzy search I bound ctrl+r to fzf (you can use Rust's sk too).