Skip to content

Commit a521082

Browse files
committed
feat: launch using ghostty when available
1 parent 071c754 commit a521082

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

victoria.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import re
1818
import shutil
19+
import shlex
1920
import subprocess
2021
import sys
2122
import tempfile
@@ -58,6 +59,47 @@ def ensure_default_files():
5859
"SNOWFLAKE_ROLE",
5960
]
6061

62+
63+
def relaunch_in_terminal() -> bool:
64+
"""Relaunch this script in a terminal window.
65+
66+
Prefers Ghostty when available on macOS or Linux. Falls back to the
67+
default system terminal when Ghostty isn't installed. Returns True if a
68+
new terminal was spawned and the caller should exit."""
69+
70+
if os.environ.get("VICTORIA_IN_TERMINAL"):
71+
return False
72+
73+
cmd: List[str] = [sys.executable, str(Path(__file__).resolve())] + sys.argv[1:]
74+
env = os.environ.copy()
75+
env["VICTORIA_IN_TERMINAL"] = "1"
76+
77+
ghostty = shutil.which("ghostty")
78+
if ghostty and sys.platform != "win32":
79+
try:
80+
subprocess.Popen([ghostty, "-e", *cmd], env=env)
81+
return True
82+
except Exception:
83+
pass
84+
85+
if sys.platform == "darwin":
86+
try:
87+
osa_cmd = f'tell application "Terminal" to do script "{shlex.join(cmd)}"'
88+
subprocess.Popen(["osascript", "-e", osa_cmd], env=env)
89+
return True
90+
except Exception:
91+
pass
92+
elif sys.platform.startswith("linux"):
93+
term = shutil.which("x-terminal-emulator")
94+
if term:
95+
try:
96+
subprocess.Popen([term, "-e", *cmd], env=env)
97+
return True
98+
except Exception:
99+
pass
100+
101+
return False
102+
61103
# ------------------ Terminal Capability Detection ------------------
62104
def _enable_windows_ansi():
63105
"""Best-effort enable ANSI on Windows without external deps."""
@@ -777,6 +819,8 @@ def main():
777819
launch_tool()
778820

779821
if __name__ == "__main__":
822+
if relaunch_in_terminal():
823+
sys.exit(0)
780824
try:
781825
main()
782826
except KeyboardInterrupt:

0 commit comments

Comments
 (0)