💾 Archived View for dioskouroi.xyz › thread › 29443334 captured on 2021-12-04 at 18:04:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

➡️ Next capture (2021-12-05)

-=-=-=-=-=-=-

ZSH Completions How To

Author: ossusermivami

Score: 69

Comments: 11

Date: 2021-12-04 18:58:30

Web Link

________________________________________________________________________________

boibombeiro wrote at 2021-12-04 21:08:58:

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.

GhettoComputers wrote at 2021-12-04 21:56:39:

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.

cassianoleal wrote at 2021-12-04 20:14:55:

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:

$  grep kubectl ~/.zcompdump
    'kubectl' '_bash_complete -o default -F __start_kubectl'
    autoload -Uz _bat _brew _git _j _kubectl \

[0]

https://github.com/sbstp/kubie

maven29 wrote at 2021-12-04 20:49:01:

Why not generate them from the manpages [1] or from the output of the --help option [2]

[1]

https://github.com/nevesnunes/sh-manpage-completions

[2]

https://github.com/RobSis/zsh-completion-generator

GhettoComputers wrote at 2021-12-04 20:15:38:

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.

beebmam wrote at 2021-12-04 20:40:04:

I really, really don't like completions as a feature in virtually any shell. I much prefer reverse search.

GhettoComputers wrote at 2021-12-04 21:59:33:

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.

Fnoord wrote at 2021-12-04 22:44:38:

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).

ivank wrote at 2021-12-04 21:07:03:

Were you thinking of autosuggestions? (completions are command-specific assistance you get when you hit Tab)

HellsMaddy wrote at 2021-12-04 20:49:24:

These things are not mutually exclusive, right? I use both to great effect.

Bayart wrote at 2021-12-04 21:41:06:

You can have both.