Skip to content

fix: respect ZDOTDIR env var for zsh completion install#1733

Closed
zons-zhaozhy wants to merge 1 commit into
fastapi:masterfrom
zons-zhaozhy:fix/zdotdir-zsh-completion
Closed

fix: respect ZDOTDIR env var for zsh completion install#1733
zons-zhaozhy wants to merge 1 commit into
fastapi:masterfrom
zons-zhaozhy:fix/zdotdir-zsh-completion

Conversation

@zons-zhaozhy
Copy link
Copy Markdown

Summary

Respect the ZDOTDIR environment variable when installing zsh completion.

Problem

When running --install-completion zsh, Typer always writes to $HOME/.zshrc. However, zsh supports the ZDOTDIR environment variable to override the directory where .zshrc lives. Users who set ZDOTDIR (e.g., export ZDOTDIR=~/.config/zsh) have their completion installed to the wrong file.

Fix

In install_zsh(), check os.environ.get("ZDOTDIR") and use it as the base directory for .zshrc instead of always using $HOME. Falls back to $HOME when ZDOTDIR is not set.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Fixes #171

Zsh uses $ZDOTDIR/.zshrc instead of $HOME/.zshrc when ZDOTDIR is set.
The install_zsh function was always writing to $HOME/.zshrc, ignoring
the ZDOTDIR environment variable.

Fixes fastapi#171
Copy link
Copy Markdown
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.

Duplicate of #1553 - closing.

@svlandeg svlandeg closed this May 5, 2026
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

4 participants