argcomplete icon indicating copy to clipboard operation
argcomplete copied to clipboard

add native zsh support

Open haifengkao opened this issue 9 years ago • 11 comments

The codes of _python_argcomplete_zsh are mostly copied from _bash_complete in bashcompinit. I don't really know how to do bash programming, so I made the pull request with copy-n-paste-programming and programming-by-coincidence techniques. I believe it will require a serious review.

It does

  • use the native zsh completion system, so autoload bashcompinit is not required anymore (https://github.com/kislyuk/argcomplete/issues/135)
  • preserve the completion order from the python scripts (zsh only https://github.com/kislyuk/argcomplete/issues/129)
  • allow arbitrary completion even the prefix doesn't match the user input (zsh only https://github.com/kislyuk/argcomplete/issues/139)

haifengkao avatar Aug 01 '16 19:08 haifengkao

Current coverage is 78.07% (diff: 100%)

Merging #141 into master will decrease coverage by 3.05%

@@             master       #141   diff @@
==========================================
  Files             5          5          
  Lines           816        789    -27   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits            662        616    -46   
- Misses          154        173    +19   
  Partials          0          0          

Powered by Codecov. Last update c0d9d23...42ea592

codecov-io avatar Aug 01 '16 19:08 codecov-io

As we discussed previously, we will need an end-to-end test harness in the test suite which can use pexpect to call the completion hook from bash and zsh, and test the expected result. We will also need the tests to pass. That is the starting point where I can begin to actually review this PR.

kislyuk avatar Aug 02 '16 20:08 kislyuk

Got it. The bash/zsh testing environment is a huge work.

haifengkao avatar Aug 03 '16 01:08 haifengkao

The strange space issue is explained in https://github.com/kislyuk/argcomplete/issues/50

haifengkao avatar Aug 03 '16 06:08 haifengkao

#153 should give you a decent start on the pexpect tests. Running those tests now shows that these changes break bash.

evanunderscore avatar Oct 16 '16 13:10 evanunderscore

I may need some time to work on this one.

haifengkao avatar Oct 17 '16 11:10 haifengkao

I had a quick look at getting the testing to work with zsh, and it's a bit more difficult. There's no zsh equivalent of pexpect.replwrap.bash, so you'll have to look at how that's implemented and build your own. I found that even after setting PS1 it was still printing a bunch of other characters. However once you have that working you should be able to get all the bash tests free via subclassing.

evanunderscore avatar Oct 17 '16 12:10 evanunderscore

What's the status of this PR? I see that it breaks bash support but is it ready to use for zsh-only completion? I've tried using bash completions scripts with bashcompinit but most of these completions just don't work.

sergei-dyshel avatar Nov 08 '17 18:11 sergei-dyshel

I don't really use bash, so I don't know what is supposed to work. A simple ls completion works on bash.

haifengkao avatar Nov 09 '17 06:11 haifengkao

@sergei-dyshel, as you can see from the discussion above, the author of this PR has not been able to provide a test suite for the changes. The author also doesn't have a complete understanding of what's going on in the zsh completion loop, as is evident from the comments and complexity in the zsh completion harness that he wrote. Since I don't use zsh and don't have the time to learn it for this purpose, I can't contribute and this PR is stuck.

As far as I understand, zsh completion should work in argcomplete through the zsh bashcompinit layer (although we don't have tests for this in our test suite). Can you describe in detail the test that you performed that made you think it doesn't work?

kislyuk avatar Nov 10 '17 18:11 kislyuk

@kislyuk Thank you for your harsh but true comment. I think it is better to wait for someone who has the deep understanding of zsh completion to merge this PR. I use this PR on a daily basis. It will work, but I don't know why.

haifengkao avatar Nov 16 '17 05:11 haifengkao

zsh support was added in v3.0.0 using different shellcode.

kislyuk avatar Mar 19 '23 23:03 kislyuk