Merge branch 'main' into zshell-img-tools
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from typer._completion_shared import install, _get_shell_name
|
from typer._completion_shared import install, _get_shell_name
|
||||||
|
from typer._completion_classes import completion_init
|
||||||
from zshell.subcommands import shell, scheme, screenshot, wallpaper, record
|
from zshell.subcommands import shell, scheme, screenshot, wallpaper, record
|
||||||
|
|
||||||
app = typer.Typer(name="zshell-cli", add_completion=False)
|
app = typer.Typer(name="zshell-cli", add_completion=False)
|
||||||
@@ -30,23 +32,26 @@ def _completion_installed() -> bool:
|
|||||||
def _install_completion() -> None:
|
def _install_completion() -> None:
|
||||||
if _completion_installed():
|
if _completion_installed():
|
||||||
print("zshell-cli: Shell completion already installed.")
|
print("zshell-cli: Shell completion already installed.")
|
||||||
raise typer.Exit()
|
sys.exit(0)
|
||||||
shell = _get_shell_name()
|
shell = _get_shell_name()
|
||||||
if shell is None:
|
if shell is None:
|
||||||
print("zshell-cli: Unable to detect shell type.", file=sys.stderr)
|
print("zshell-cli: Unable to detect shell type.", file=sys.stderr)
|
||||||
raise typer.Exit(code=1)
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
_, path = install(prog_name="zshell-cli")
|
_, path = install(prog_name="zshell-cli")
|
||||||
print(f"zshell-cli: Shell completion installed ({shell}: {path})")
|
print(f"zshell-cli: Shell completion installed ({shell}: {path})")
|
||||||
print("zshell-cli: Restart your shell or source the file to enable tab-completion.")
|
print("zshell-cli: Restart your shell or source the file to enable tab-completion.")
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
print(f"zshell-cli: Failed to install shell completion: {e}", file=sys.stderr)
|
||||||
|
raise typer.Exit(code=1)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
if "--install-autocomplete" in sys.argv:
|
if "--install-autocomplete" in sys.argv:
|
||||||
_install_completion()
|
_install_completion()
|
||||||
return
|
return
|
||||||
|
if "_ZSHELL_CLI_COMPLETE" in os.environ:
|
||||||
|
completion_init()
|
||||||
if sys.stdout.isatty() and not _completion_installed():
|
if sys.stdout.isatty() and not _completion_installed():
|
||||||
print("zshell-cli: Tip: run with --install-autocomplete for tab completion.", file=sys.stderr)
|
print("zshell-cli: Tip: run with --install-autocomplete for tab completion.", file=sys.stderr)
|
||||||
app()
|
app()
|
||||||
|
|||||||
Reference in New Issue
Block a user