[HN Gopher] ZSH Completions How To
___________________________________________________________________
ZSH Completions How To
Author : ossusermivami
Score : 67 points
Date : 2021-12-04 18:58 UTC (4 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| beebmam wrote:
| I really, really don't like completions as a feature in virtually
| any shell. I much prefer reverse search.
| GhettoComputers wrote:
| 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:
| 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).
| HellsMaddy wrote:
| These things are not mutually exclusive, right? I use both to
| great effect.
| Bayart wrote:
| You can have both.
| ivank wrote:
| Were you thinking of autosuggestions? (completions are command-
| specific assistance you get when you hit Tab)
| cassianoleal wrote:
| 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
| GhettoComputers wrote:
| 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.
| maven29 wrote:
| 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
| boibombeiro wrote:
| 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:
| 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.
___________________________________________________________________
(page generated 2021-12-04 23:00 UTC)