Skip to content

Fix zsh completion to respect ZDOTDIR env var#1553

Open
Fridayai700 wants to merge 1 commit intofastapi:masterfrom
Fridayai700:fix-zsh-zdotdir-171
Open

Fix zsh completion to respect ZDOTDIR env var#1553
Fridayai700 wants to merge 1 commit intofastapi:masterfrom
Fridayai700:fix-zsh-zdotdir-171

Conversation

@Fridayai700
Copy link

Type of changes

  • Bug fix

AI?

  • AI was used to generate this PR

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate (see note about typos above).
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Fixes #171

When installing zsh autocompletion, install_zsh() hardcoded Path.home() for both .zshrc and .zfunc/ paths. This ignores the ZDOTDIR environment variable, which zsh uses to locate user startup files.

The fix:

  • Check os.environ.get("ZDOTDIR") and use it as the base directory when set
  • Fall back to Path.home() when ZDOTDIR is not set (preserving existing behavior)
  • Use $ZDOTDIR/.zfunc in the fpath line when ZDOTDIR is set (zsh expands this at startup), ~/.zfunc otherwise

Test added: test_completion_install_zsh_zdotdir — creates a temp directory as ZDOTDIR, runs completion install, verifies .zshrc and .zfunc/ are created in the ZDOTDIR location.

All existing completion install tests continue to pass.

Closes fastapi#171

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant