Closed Gim6626 closed 3 years ago
Thanks for reporting! I don't have a Mac, so I'd be happy if you gave me some help in the debugging process (Should probably get a docker for this in the future).
First things first: Did you try restarting zsh
after the files were copied? If you don't do this then zsh
wouldn't know they exist as it searches for them when it starts up. You can also type into your terminal _python_or_script
or _python_script
and see if it recognizes them.
If they are still unrecognized it might be you need to put them in a nested directory. From what I see on Ubuntu, my FPATH
variable contains a lot of directories nested under /usr/share/zsh/functions
, but not the directory itself. So moving the scripts into, say, /usr/local/share/zsh/site-functions/Completion/Unix
should work (assuming that's where completion scripts are found on Mac). Don't forget to restart zsh
afterwards.
If the scripts are recognized, then please provide the following: a MVP showing a script with completion that doesn't work + the debugging output of zsh
for attempted completion. You can do this by writing the partial command line prior to completion and pressing ctrl+x+?
instead of tab
(e.g. python my_script.py <ctrl+x+?>
. zsh
should show you the name of a log file with the output.
Thanks for reporting!
Thanks for your work on this project!
Did you try restarting zsh after the files were copied?
Of course I did. That was not a problem.
Speaking about my issue - seems that I found solution. Tried to setup from scratch on other Mac - it worked.
At first, target_dir
should be replaced before activate_pyzshcomplete
execution as I've written if first post.
Second, this lines should be added to .zshrc
:
autoload -Uz compinit
compinit
Then restart zsh and autocomplete should start working.
Also, if you get “insecure directories” error while starting zsh like this:
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]?
you should type “y“ and then run compaudit
, you will get something like this:
There are insecure directories:
/usr/local/share/zsh/site-functions
/usr/local/share/zsh
This is list of trouble directories. To fix it you should run following command for each directory listed in compaudit output:
sudo chmod 755 DIRECTORY
On next zsh start everything should be fine. But you may not face this issue at all, on second Mac which I tried there was no such issue.
If I'm correct, then no autocompletion should have worked prior to adding compinit
to your .zshrc
(not just for python
).
Are you not using Oh My Zsh
by any chance? Because I think it takes care of all of these things (see oh-my-zsh.sh). I can't recommend it enough as it takes care of all the boiler plate of zsh
for you.
I'll add a section for prerequisites such as making sure autocompletion is enabled in zsh
, and provide a fix for the script on Macs.
If I'm correct, then no autocompletion should have worked
Without compinit
lines at least commands and files names autocomplete works. Are there any other autocomplete features that I should check?
Are you not using Oh My Zsh by any chance?
I even don't know what is it :) I've got clear zsh as it is installed on macOS without any addons.
Actually I'm not very familiar with zsh and could understand something wrongly. I use bash and just needed to check if autocomplete for my work Python script is ok in zsh.
Are there any other autocomplete features that I should check?
You could try checking out things like ps
and see if you get all the flags and process numbers. zsh
may have a basic autocomplete for filenames that works without compinit
but I'm not sure.
I use bash and just needed to check if autocomplete for my work Python script is ok in zsh.
If you want to stay with bash
you can use argcomplete (which this project was inspired by).
I even don't know what is it :) I've got clear zsh as it is installed on macOS without any addons.
Oh My Zsh is a community driven projects aimed at configuring zsh
and providing a lot of customization to the user (such as themes and plugins). I don't know a single person who uses zsh
without it. They have an easy installation process documented in their readme.
I tried to use
argcomplete
in zsh but could not make it work. Then I foundpyzshcomplete
and decided to try it. I've installedpip
package tovirtualenv
on my MacBook, tried to execute~/.local/bin/activate_pyzshcomplete
as it was described in docs https://pypi.org/project/pyzshcomplete/ but there was no such script. I foundenv/bin/activate_pyzshcomplete
, tried it and got:Then I looked at code and tried to replace
target_dir
inzsh_completion_function_dir
function to/usr/local/share/zsh/site-functions/
(found in https://stackoverflow.com/a/25292346/1927853 that completion scripts are there), files_python_or_script
and_python_script
appears, but completion does not work too.So I've created issue here.
Please help me.