fastapi / typer

Typer, build great CLIs. Easy to code. Based on Python type hints.
https://typer.tiangolo.com/
MIT License
15.44k stars 656 forks source link

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

Open m-rey opened 3 years ago

m-rey commented 3 years ago

Describe the bug

When autocompletion is created in typer, the necessary changes are made in $HOME/.zshrc: https://github.com/tiangolo/typer/blob/a93e6b2f86a34fd82741ae837b9b188083a5e9c0/typer/completion.py#L225 However, the path to the directory where the .zshrc file is in, can be set by the environment variable ZDOTDIR. Therefore, typer should check first if the environment variable ZDOTDIR is set and valid and use it to find .zshrc and add the necessary line for auto-completion. If it is invalid or simply not set, the default path to $HOME/.zshrc can be used.

To Reproduce

zsh
mkdir "$HOME/not_default_zsh_dir"
touch "$HOME/not_default_zsh_dir/.zshrc"
export ZDOTDIR="$HOME/not_default_zsh_dir"
# try using the typer autocompletion now, it should fail

Expected behavior

typer should check for the ZDOTDIR env var and use it as base to locate .zshrc instead of always using HOME.

mjmare commented 3 years ago

Bug still present in Typer 0.3.2