This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
APP_NAME = "browser-cli"
|
||||
RUNTIME_DIRNAME = ".browser_cli"
|
||||
DEFAULT_ALIAS = "default"
|
||||
|
||||
def is_windows() -> bool:
|
||||
return sys.platform.startswith("win")
|
||||
|
||||
def runtime_dir() -> Path:
|
||||
if is_windows():
|
||||
base = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
|
||||
return base / APP_NAME
|
||||
return Path("/tmp") / RUNTIME_DIRNAME
|
||||
|
||||
def registry_path() -> Path:
|
||||
return runtime_dir() / "registry.json"
|
||||
|
||||
def install_base_dir() -> Path:
|
||||
if is_windows():
|
||||
return runtime_dir()
|
||||
if sys.platform == "darwin":
|
||||
return Path.home() / "Library" / "Application Support" / APP_NAME
|
||||
return Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share")) / APP_NAME
|
||||
|
||||
def sanitize_alias(alias:str) -> str:
|
||||
cleaned = "".join(ch if ch.isalnum() or ch in "._-" else "_" for ch in alias.strip())
|
||||
return cleaned or DEFAULT_ALIAS
|
||||
|
||||
def endpoint_for_alias(alias:str) -> str:
|
||||
safe = sanitize_alias(alias)
|
||||
if is_windows():
|
||||
return rf"\\.\pipe\browser-cli-{safe}"
|
||||
return str(runtime_dir() / f"{safe}.sock")
|
||||
Reference in New Issue
Block a user