Host listens on a unix socket; tabbed-run sends a command to open it as a new maximized casilda tab. Spawned children inherit the full environment plus TABBED_CASILDA_CTRL so tabbed-run works from any tab.
24 lines
659 B
Python
Executable file
24 lines
659 B
Python
Executable file
#!/usr/bin/env python3
|
|
import os
|
|
import shlex
|
|
import socket
|
|
import sys
|
|
|
|
ctrl = os.environ.get("TABBED_CASILDA_CTRL")
|
|
if not ctrl:
|
|
print(
|
|
"tabbed-run: TABBED_CASILDA_CTRL not set (run inside a tabbed-casilda terminal)",
|
|
file=sys.stderr,
|
|
)
|
|
sys.exit(1)
|
|
if len(sys.argv) < 2:
|
|
print("usage: tabbed-run COMMAND [ARGS...]", file=sys.stderr)
|
|
sys.exit(1)
|
|
payload = (shlex.join(sys.argv[1:]) + "\n").encode()
|
|
try:
|
|
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
|
|
s.connect(ctrl)
|
|
s.sendall(payload)
|
|
except OSError as e:
|
|
print(f"tabbed-run: cannot reach host: {e}", file=sys.stderr)
|
|
sys.exit(1)
|