add new search engine commands

This commit is contained in:
2026-04-09 08:44:56 +02:00
parent ab4ba97886
commit 50dc2bb5e5
2 changed files with 107 additions and 14 deletions
+17 -14
View File
@@ -17,6 +17,7 @@ from browser_cli.commands.windows import windows_group
from browser_cli.commands.dom import dom_group
from browser_cli.commands.extract import extract_group
from browser_cli.commands.session import session_group
from browser_cli.commands.search import search_group
from browser_cli.client import send_command, BrowserNotConnected
console = Console()
@@ -52,6 +53,7 @@ main.add_command(windows_group)
main.add_command(dom_group)
main.add_command(extract_group)
main.add_command(session_group)
main.add_command(search_group)
# ── clients ────────────────────────────────────────────────────────────────────
@@ -118,20 +120,12 @@ def cmd_rename_profile(alias):
def cmd_install(browser):
"""Register the native messaging host and print extension load instructions."""
# Find the venv entry point for the native host (stable regardless of project location)
venv_script = Path(sys.executable).parent / "browser-cli-native-host"
if not venv_script.exists():
console.print(f"[red]Cannot find browser-cli-native-host in venv ({venv_script})[/red]")
console.print(" Run [cyan]uv sync[/cyan] first to install entry points.")
sys.exit(1)
# Install wrapper to ~/.local/bin so the manifest path never changes
local_bin = Path.home() / ".local" / "bin"
local_bin.mkdir(parents=True, exist_ok=True)
wrapper_path = local_bin / "browser-cli-native-host"
wrapper_content = f"""#!/bin/sh
exec "{venv_script}" "$@"
"""
# Install wrapper outside PATH — Chrome uses the absolute path from the manifest,
# so it doesn't need to be a shell command.
share_dir = Path.home() / ".local" / "share" / "browser-cli"
share_dir.mkdir(parents=True, exist_ok=True)
wrapper_path = share_dir / "native-host"
wrapper_content = f'#!/bin/sh\nexec "{sys.executable}" -m browser_cli.native_host "$@"\n'
wrapper_path.write_text(wrapper_content)
wrapper_path.chmod(wrapper_path.stat().st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
@@ -181,6 +175,15 @@ exec "{venv_script}" "$@"
console.print(" After restarting Chrome, try: [cyan]browser-cli tabs list[/cyan]")
# ── native-host (hidden, called by Chrome via native messaging) ────────────────
@main.command("native-host", hidden=True)
def cmd_native_host():
"""Native messaging host — called by Chrome, not for direct use."""
from browser_cli.native_host import main as _main
_main()
# ── completion ─────────────────────────────────────────────────────────────────
@main.command("completion")