From d19eead1f53dcddf09c4cb8e23d857f496f10380 Mon Sep 17 00:00:00 2001 From: AramJonghu Date: Tue, 26 May 2026 09:25:06 +0200 Subject: [PATCH] autocomplete now optional. Includes hint on first command input --- cli/src/zshell/__init__.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cli/src/zshell/__init__.py b/cli/src/zshell/__init__.py index 9622faf..8e101e2 100644 --- a/cli/src/zshell/__init__.py +++ b/cli/src/zshell/__init__.py @@ -28,14 +28,14 @@ def _completion_installed() -> bool: return False -def _auto_install_completion() -> None: - if not sys.stdout.isatty(): - return +def _install_completion() -> None: if _completion_installed(): - return + click.echo("zshell-cli: Shell completion already installed.") + raise typer.Exit() shell = _get_shell_name() if shell is None: - return + click.echo("zshell-cli: Unable to detect shell type.", err=True) + raise typer.Exit(code=1) try: _, path = install(prog_name="zshell-cli") click.secho(f"zshell-cli: Shell completion installed ({shell}: {path})", fg="green") @@ -44,6 +44,16 @@ def _auto_install_completion() -> None: pass +@app.callback() +def main_options( + install_autocomplete: bool = typer.Option(False, "--install-autocomplete", help="Install shell completion for tab-completion."), +): + if install_autocomplete: + _install_completion() + raise typer.Exit() + + def main() -> None: - _auto_install_completion() + if sys.stdout.isatty() and not _completion_installed(): + click.echo("zshell-cli: Tip: run with --install-autocomplete for tab completion.", err=True) app()