Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ZDOTDIR in zsh completion #870

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chrishepner
Copy link

@chrishepner chrishepner commented Jun 24, 2024

zsh supports placing its startup files in a directory other than $HOME, when the user specifies $ZDOTDIR in ~/.zshenv.

typer currently always writes to ~/.zshrc and ~/.zfunc. This means that for users that have $ZDOTDIR set to something other than $HOME, typer --install-completion has no functional effect on the user's shell.

Update install_zsh to install completion to $ZDOTDIR/.zshrc and $ZDOTDIR/.zfunc/ when set.

@chrishepner chrishepner force-pushed the support-ZDOTDIR branch 2 times, most recently from f6aff9e to 6a40926 Compare June 24, 2024 04:46
zsh supports placing its startup files in a directory other than $HOME, [when the user specifies $ZDOTDIR in ~/.zshenv](https://zsh.sourceforge.io/Intro/intro_3.html).

typer currently always writes to `~/.zshrc` and `~/.zfunc`. This means that for users that have $ZDOTDIR set to something other than $HOME, `typer --install-completion` has no effect.

Update `install_zsh` to install completion to `$ZDOTDIR/.zshrc` and `$ZDOTDIR/.zfunc/` when set.
@chrishepner
Copy link
Author

Hmm, it looks like the absolute fpath breaks the test on Windows. Is zsh completion meaningful on Windows? I'm not sure if this is a meaningful regression or something I should suppress.

@svlandeg svlandeg added feature New feature, enhancement or request autocompletion p3 labels Jun 24, 2024
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR!

I believe there are ways to use zsh on Windows with Git Bash, though I have no experience with it myself. Either way, the test was working before so it feels like we should be able to get this simple check working on Windows as well.

I double checked on a Windows system to see what was going on, and it seems like the subprocess.run call isn't actually executed properly. The content of new_text is still echo "custom .zshrc" when the assert fails. So I don't think the issue is with fpath.

result.stderr contains the following:

Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python

Which seems to point at an issue with the runtime environment, probably due to the way how you've used mock.patch.dict to make changes to os.environ. Can you think of a different way to run this check?

[UPDATE]: I can indeed use zsh on Windows with Git Bash, so I do think this is a meaningful regression.

@svlandeg svlandeg self-assigned this Aug 5, 2024
@svlandeg svlandeg removed their assignment Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature, enhancement or request p3 shell / zsh
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] typer doesn't respect ZDOTDIR env var when adding autocompletion for zsh
2 participants