dsifford / yarn-completion

Bash completion for Yarn
MIT License
277 stars 25 forks source link

Zsh support? #35

Open borekb opened 5 years ago

borekb commented 5 years ago

Hi, I don't know how completions work internally and whether completions for Zsh are something completely different than completions for Bash but it would be awesome if this package worked in both shells. Is that technically possible?

BTW, these Yarn completions are way more advanced than anything else I have seen (for zsh at least), for example, parsing workspaces from package.json as per https://github.com/dsifford/yarn-completion/issues/29 is the right thing to do while most other completions don't support Yarn workspaces at all.

dsifford commented 5 years ago

Officially supported zsh completions can be found here.

Unfortunately, the completions for bash and zsh are implemented in an entirely different way, so there's no real great way to interop (that I'm aware of).

See #30 for discussion on some issues with parsing workspaces using package.json.

borekb commented 5 years ago

For anyone interested, I managed to make it work this way:

  1. Add this shopt script somewhere in your $PATH.
  2. autoload bashcompinit && bashcompinit
  3. source yarn-completion.bash

Screenshot 2019-04-09 at 19 16 46

borekb commented 5 years ago

@dsifford if you don't mind I'll use this issue to gather pieces of information about the possible Zsh support. (Disclaimer: I know very little about how the completions work internally in either Bash or Zsh so won't probably be able to help myself.)

Current situation:

What I found in Zsh docs is simply this:

The function bashcompinit provides compatibility with bash’s programmable completion system. When run it will define the functions, compgen and complete which correspond to the bash builtins with the same names. It will then be possible to use completion specifications and functions written for bash.

I also have zsh-users/zsh-completions installed which has this file in it, which seems to implement the compgen and complete functions as well. I'm not sure if it's loaded and how, and how it interacts with the built-in bashcompinit from Zsh.

I also don't know how to troubleshoot issues with autocompletion – the suggestions are simply weird but there are no error messages anywhere.

dsifford commented 5 years ago

@borekb Open up a new issue so others can find it easier. That way we might get lucky and have someone stumble upon it and help.

Re: your disclaimer -- I had no idea how bash completions worked and have never wrote a bash completion script in my life prior to making this one. It's tricky at first to understand, but I'm proof that it's possible. Don't sell yourself short.

borekb commented 5 years ago

If it was writing completions for a single known environment, maybe I could try to do that but this sounds like troubleshooting of some (delicate?) interactions / integrations between Zsh and Bash which I really don't think I'd be capable of 😄.

How about re-opening this issue? "Zsh support" as a title sounds pretty good to me.

dsifford commented 5 years ago

Whoops, sorry... Thought this was the PR I commented on.

Yep, we can reopen this one. :+1: