From a0a799c2b5a346d092139b19f9d27c2db607f894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B3=A5=E8=B1=86?= <1243352777@qq.com> Date: Tue, 5 May 2026 19:38:17 +0800 Subject: [PATCH] fix: respect ZDOTDIR env var for zsh completion install 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 #171 --- typer/_completion_shared.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/typer/_completion_shared.py b/typer/_completion_shared.py index 5a81dcf68c..07ad1ecfbc 100644 --- a/typer/_completion_shared.py +++ b/typer/_completion_shared.py @@ -118,7 +118,9 @@ def install_bash(*, prog_name: str, complete_var: str, shell: str) -> Path: def install_zsh(*, prog_name: str, complete_var: str, shell: str) -> Path: # Setup Zsh and load ~/.zfunc - zshrc_path = Path.home() / ".zshrc" + # Respect ZDOTDIR: zsh uses $ZDOTDIR/.zshrc instead of $HOME/.zshrc + zdotdir = Path(os.environ.get("ZDOTDIR", Path.home())) + zshrc_path = zdotdir / ".zshrc" zshrc_path.parent.mkdir(parents=True, exist_ok=True) zshrc_content = "" if zshrc_path.is_file():