I hate how complex it to write a decent zsh completion. It is not something you can realistic do in a weekend.
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.
Fish has sane defaults. I don’t think using shell scripts is a great idea. The creator of oil shell pops up pretty often, he has some default scripts that might be useful for some. Also I should add you can use it interactively in bash. https://wiki.archlinux.org/title/fish#Setting_fish_as_intera...
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 have an edge-case for zsh completion that I'd love to know if there's a way to implement.
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:
I’ve spend hours trying to get it to work as well as fish, but even the installed configs I miss one thing or another and autocomplete is still missing features. It’s a mess and really slow.
Without 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 not always ideal, only you have a very intelligent parser understanding the context of the manpage.. i.e: "-u: read a http url" the parser would need to understand to propose an https:// (and perhaps the hosts on system) prefix after hitting the TAB key after the -u flag. if not it would do just the completion of switches and argument which is maybe good enough but not great...
(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)
Love zsh + OhMyZsh. But one thing I repeatedly wish it had but maybe I just need to read the manual: when I type the start of a command, says “python”, I want to search for a previous command that starts with “python” and contains the string “data2134”. I tried Ctl-R but that doesn’t seem to be it.
Have you tried fish? You can partially complete the query and use the arrow buttons, and the search is fuzzy if you use the previous commands search. Typing Sudo for instance and arrow will show my previous sudod commands.
Yup, its great. Problem is, the syntax is slightly different from Bash. So whenever I use a shell script or use some kind of commands where the differences are incompatible, I tend to switch to Bash. And then my history doesn't add up with the one from Fish.
For fuzzy search I bound ctrl+r to fzf (you can use Rust's sk too).
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.