Skip to content

Commit

Permalink
🐛 Fix zsh autocompletion installation (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: svlandeg <svlandeg@github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
  • Loading branch information
4 people authored Aug 17, 2024
1 parent 90f3e61 commit 640fb09
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions typer/_completion_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ 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"
completion_line = "fpath+=~/.zfunc; autoload -Uz compinit; compinit"
if completion_line not in zshrc_content:
zshrc_content += f"\n{completion_line}\n"
style_line = "zstyle ':completion:*' menu select"
# TODO: consider setting the style only for the current program
# style_line = f"zstyle ':completion:*:*:{prog_name}:*' menu select"
# Install zstyle completion config only if the user doesn't have a customization
if "zstyle" not in zshrc_content:
zshrc_content += f"\n{style_line}\n"
zshrc_content = f"{zshrc_content.strip()}\n"
zshrc_path.write_text(zshrc_content)
# Install completion under ~/.zfunc/
path_obj = Path.home() / f".zfunc/_{prog_name}"
Expand Down

0 comments on commit 640fb09

Please sign in to comment.