chore: attach when starting relay tmux session
This commit is contained in:
@@ -2,7 +2,10 @@ import { spawn } from "node:child_process";
|
||||
|
||||
const SESSION = "warelay-relay";
|
||||
|
||||
export async function spawnRelayTmux(cmd = "pnpm warelay relay --verbose") {
|
||||
export async function spawnRelayTmux(
|
||||
cmd = "pnpm warelay relay --verbose",
|
||||
attach = true,
|
||||
) {
|
||||
await killSession(SESSION);
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const child = spawn("tmux", ["new", "-d", "-s", SESSION, cmd], {
|
||||
@@ -15,6 +18,21 @@ export async function spawnRelayTmux(cmd = "pnpm warelay relay --verbose") {
|
||||
else reject(new Error(`tmux exited with code ${code}`));
|
||||
});
|
||||
});
|
||||
|
||||
if (attach) {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const child = spawn("tmux", ["attach-session", "-t", SESSION], {
|
||||
stdio: "inherit",
|
||||
shell: false,
|
||||
});
|
||||
child.on("error", reject);
|
||||
child.on("exit", (code) => {
|
||||
if (code === 0) resolve();
|
||||
else reject(new Error(`tmux attach exited with code ${code}`));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return SESSION;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user