From 9e34726efad3e6bf00b5ad88a7ee45da1d1da6fd Mon Sep 17 00:00:00 2001 From: Alex Jurkiewicz Date: Tue, 23 Feb 2021 09:23:13 +1100 Subject: [PATCH 1/6] Remove zsh autocomplete styling This is an opinionated change that can affect users existing completion configuration. --- typer/completion.py | 1 - 1 file changed, 1 deletion(-) diff --git a/typer/completion.py b/typer/completion.py index 4a0b01251d..781c1096a3 100644 --- a/typer/completion.py +++ b/typer/completion.py @@ -230,7 +230,6 @@ def install_zsh(*, prog_name: str, complete_var: str, shell: str) -> Path: completion_init_lines = [ "autoload -Uz compinit", "compinit", - "zstyle ':completion:*' menu select", "fpath+=~/.zfunc", ] for line in completion_init_lines: From 73fee869a6d76256f1a74e6ca173df6a1a426d48 Mon Sep 17 00:00:00 2001 From: Alex Jurkiewicz Date: Tue, 23 Feb 2021 09:40:23 +1100 Subject: [PATCH 2/6] Fix zsh autocomplete ordering compinit must be run after fpath is updated, to load new completions. Don't add extraneous newlines at the end of zshrc. --- typer/completion.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/typer/completion.py b/typer/completion.py index 781c1096a3..17b3bd45b1 100644 --- a/typer/completion.py +++ b/typer/completion.py @@ -227,15 +227,11 @@ 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", - "fpath+=~/.zfunc", - ] - for line in completion_init_lines: - if line not in zshrc_content: # pragma: nocover - zshrc_content += f"\n{line}" - zshrc_content += "\n" + if "autoload -Uz compinit" not in zshrc_content: # pragma: nocover + zshrc_content += f"\nautoload -Uz compinit" + if "fpath+=~/.zfunc" not in zshrc_content: # pragma: nocover + zshrc_content += f"\nfpath+=~/.zfunc\ncompinit" + zshrc_content = f"{zshrc_content.rstrip('\n')}" zshrc_path.write_text(zshrc_content) # Install completion under ~/.zfunc/ path_obj = Path.home() / f".zfunc/_{prog_name}" From 903b2a82059997cb41980cfed2526c27adc9920c Mon Sep 17 00:00:00 2001 From: Alex Jurkiewicz Date: Tue, 23 Feb 2021 09:59:53 +1100 Subject: [PATCH 3/6] Fix zshrc EOF newline logic --- typer/completion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/typer/completion.py b/typer/completion.py index 17b3bd45b1..6be7b3d2a5 100644 --- a/typer/completion.py +++ b/typer/completion.py @@ -231,7 +231,8 @@ def install_zsh(*, prog_name: str, complete_var: str, shell: str) -> Path: zshrc_content += f"\nautoload -Uz compinit" if "fpath+=~/.zfunc" not in zshrc_content: # pragma: nocover zshrc_content += f"\nfpath+=~/.zfunc\ncompinit" - zshrc_content = f"{zshrc_content.rstrip('\n')}" + 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}" From 067d8701b6c1d46b8afd33a21d2525a70178c2f1 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Mon, 1 Jul 2024 11:20:19 +0200 Subject: [PATCH 4/6] restore original edits --- typer/_completion_shared.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/typer/_completion_shared.py b/typer/_completion_shared.py index 10de54420d..ddc115d82a 100644 --- a/typer/_completion_shared.py +++ b/typer/_completion_shared.py @@ -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 += f"\nautoload -Uz compinit" + if "fpath+=~/.zfunc" not in zshrc_content: # pragma: nocover + zshrc_content += f"\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}" From 062bb90c356e940132af5a63a86ef17fab483cab Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 09:20:32 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/_completion_shared.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typer/_completion_shared.py b/typer/_completion_shared.py index ddc115d82a..97a5b8b9c4 100644 --- a/typer/_completion_shared.py +++ b/typer/_completion_shared.py @@ -129,9 +129,9 @@ def install_zsh(*, prog_name: str, complete_var: str, shell: str) -> Path: if zshrc_path.is_file(): zshrc_content = zshrc_path.read_text() if "autoload -Uz compinit" not in zshrc_content: # pragma: nocover - zshrc_content += f"\nautoload -Uz compinit" + zshrc_content += "\nautoload -Uz compinit" if "fpath+=~/.zfunc" not in zshrc_content: # pragma: nocover - zshrc_content += f"\nfpath+=~/.zfunc\ncompinit" + zshrc_content += "\nfpath+=~/.zfunc\ncompinit" if zshrc_content[-1] != "\n": zshrc_content += "\n" zshrc_path.write_text(zshrc_content) From e99c38f105090326bb1b0183d73343e1368d4adc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 16 Aug 2024 20:16:27 -0500 Subject: [PATCH 6/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Tweak=20implementation?= =?UTF-8?q?=20of=20zsh=20completion=20installation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- typer/_completion_shared.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/typer/_completion_shared.py b/typer/_completion_shared.py index 97a5b8b9c4..a5ff7b196a 100644 --- a/typer/_completion_shared.py +++ b/typer/_completion_shared.py @@ -128,12 +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() - 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" + 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}"