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

🐛 Fix zsh autocompletion installation #237

Merged
merged 10 commits into from
Aug 17, 2024
16 changes: 6 additions & 10 deletions typer/_completion_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,12 @@ def install_zsh(*, prog_name: str, complete_var: str, shell: str) -> Path:
zshrc_content = ""
if zshrc_path.is_file():
zshrc_content = zshrc_path.read_text()
completion_init_lines = [
"autoload -Uz compinit",
"compinit",
"zstyle ':completion:*' menu select",
"fpath+=~/.zfunc",
]
for line in completion_init_lines:
if line not in zshrc_content: # pragma: no cover
zshrc_content += f"\n{line}"
zshrc_content += "\n"
if "autoload -Uz compinit" not in zshrc_content: # pragma: nocover
zshrc_content += "\nautoload -Uz compinit"
if "fpath+=~/.zfunc" not in zshrc_content: # pragma: nocover
zshrc_content += "\nfpath+=~/.zfunc\ncompinit"
if zshrc_content[-1] != "\n":
zshrc_content += "\n"
zshrc_path.write_text(zshrc_content)
# Install completion under ~/.zfunc/
path_obj = Path.home() / f".zfunc/_{prog_name}"
Expand Down
Loading