feat(tmux): ensure automatic session logging to logs/tmux/<session>.log via pipe-pane
This commit is contained in:
+14
-1
@@ -10,10 +10,19 @@ import subprocess
|
||||
import argparse
|
||||
|
||||
SOCKET_PATH = "/tmp/tmux-muse.sock"
|
||||
LOG_DIR = "/home/super/Projects/NetVM/logs/tmux"
|
||||
TMUX_BIN = "/home/super/.local/bin/tmux"
|
||||
if not os.path.exists(TMUX_BIN):
|
||||
TMUX_BIN = "tmux"
|
||||
|
||||
def _ensure_logging(session):
|
||||
try:
|
||||
os.makedirs(LOG_DIR, exist_ok=True)
|
||||
log_file = os.path.join(LOG_DIR, f"{session}.log")
|
||||
_run_tmux("pipe-pane", "-o", "-t", session, f"cat >> {log_file}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _run_tmux(*args, capture=True):
|
||||
cmd = [TMUX_BIN, "-S", SOCKET_PATH] + list(args)
|
||||
res = subprocess.run(cmd, capture_output=capture, text=True)
|
||||
@@ -38,7 +47,8 @@ def cmd_new(args):
|
||||
|
||||
rc, out, err = _run_tmux(*t_args)
|
||||
if rc == 0:
|
||||
print(f"✔ Created session '{session}' on {SOCKET_PATH}")
|
||||
_ensure_logging(session)
|
||||
print(f"✔ Created session '{session}' on {SOCKET_PATH} (logging to logs/tmux/{session}.log)")
|
||||
return 0
|
||||
else:
|
||||
print(f"Failed to create session: {err.strip() or out.strip()}", file=sys.stderr)
|
||||
@@ -55,6 +65,9 @@ def cmd_send(args):
|
||||
# Auto-create if not exists
|
||||
print(f"Notice: Session '{session}' does not exist; creating now...", file=sys.stderr)
|
||||
_run_tmux("new-session", "-d", "-s", session)
|
||||
_ensure_logging(session)
|
||||
else:
|
||||
_ensure_logging(session)
|
||||
|
||||
t_args = ["send-keys", "-t", session, keys]
|
||||
if enter:
|
||||
|
||||
Reference in New Issue
Block a user