dan1994 / pyzshcomplete

Autocompletion for python scripts in zsh
MIT License
23 stars 4 forks source link

Don't Install in `/usr/share/..` #59

Open psacawa opened 3 years ago

psacawa commented 3 years ago

I've wanted zsh completions for pypi ecosystem for a long time, so I want to thank you for getting the ball rolling on this. My strong feeling, however, is that you shouldn't force the installation anywhere superuser privileges are required. Namely, find_completion_script_dir should prefer a user directory in fpath.

Completions for Python itself: _python are typically vendor-distributed, and therefore in /usr/share/zsh/functions/Completion/Unix. At least it's this way in Ubuntu Linux. For now I just trick it by writing a dummy file _python elsewhere.

dan1994 commented 3 years ago

Thanks for the feedback.

Honestly I would have really wanted to choose a user directory, but the thing is that there isn't always one.

I tried to check how fpath looks in a fresh zsh installation and I found it only contains paths under /usr/local and /usr/share, both of which are owned by root.

I could complicate my logic to try and find a user owned directory, and resort to the current situation as a fallback, but since I don't even know which user directory to choose I would have to guess, which may be both unwanted and unpredictable.

Another option is to update the fpath myself which requires editing the user's .zshrc, which I would also like to avoid.

The last option that comes to mind is to let the user pass in the path, which is pretty straightforward, but might still prove problematic if the user tries to upgrade and chooses a different directory (resulting in conflicting versions of the completion scripts).

I would love to hear your thoughts on these options.

eaybek commented 3 years ago

in such cases you can consider prepare a file and ask to user for source it. Just for an option

dan1994 commented 3 years ago

Thank you for the suggestion, and sorry for the late reply.

I like your suggestion and can implement it quite easily. By default running the activate script will print out a line to add to .zshrc of the form fpath=$fpath /path/to/zsh/scripts and the user will copy it manually.

dan1994 commented 3 years ago

Hey @psacawa, @eaybek. I have opened a PR that attempts to improve this issue. If you have any time to take a look and tell me if this would be a good solution for you, I'd be grateful.

The main idea is that I don't copy the files anywhere and provide the user with a line to put in their .zshrc.