pyright/ruff error fixes. Autoinstall check of autocomplete

This commit is contained in:
2026-05-25 19:03:00 +02:00
parent 17fcf1a02c
commit 32acfa6b9f
4 changed files with 61 additions and 41 deletions
+34
View File
@@ -1,5 +1,10 @@
from __future__ import annotations
import sys
from pathlib import Path
import click
import typer
from typer._completion_shared import install, _get_shell_name
from zshell.subcommands import shell, scheme, screenshot, wallpaper, record
app = typer.Typer(name="zshell-cli")
@@ -11,5 +16,34 @@ app.add_typer(wallpaper.app, name="wallpaper")
app.add_typer(record.app, name="record")
def _completion_installed() -> bool:
shell = _get_shell_name()
match shell:
case "zsh":
return (Path.home() / ".zfunc" / "_zshell-cli").exists()
case "bash":
return (Path.home() / ".bash_completions" / "zshell-cli.sh").exists()
case "fish":
return (Path.home() / ".config" / "fish" / "completions" / "zshell-cli.fish").exists()
return False
def _auto_install_completion() -> None:
if not sys.stdout.isatty():
return
if _completion_installed():
return
shell = _get_shell_name()
if shell is None:
return
try:
_, path = install(prog_name="zshell-cli")
click.secho(f"zshell-cli: Shell completion installed ({shell}: {path})", fg="green")
click.echo("zshell-cli: Restart your shell or source the file to enable tab-completion.")
except Exception:
pass
def main() -> None:
_auto_install_completion()
app()