argcomplete
argcomplete copied to clipboard
add native zsh support
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 bashcompinitis 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)
Current coverage is 78.07% (diff: 100%)
@@ 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
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.
Got it. The bash/zsh testing environment is a huge work.
The strange space issue is explained in https://github.com/kislyuk/argcomplete/issues/50
#153 should give you a decent start on the pexpect tests. Running those tests now shows that these changes break bash.
I may need some time to work on this one.
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.
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.
I don't really use bash, so I don't know what is supposed to work.
A simple ls completion works on bash.
@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 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.
zsh support was added in v3.0.0 using different shellcode.