Skip to content

Commit 788964e

Browse files
committed
isolate _pi-mux pool from tmux config that would break it
1 parent b4d014d commit 788964e

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/swap.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ function poolExists(): boolean {
120120
}
121121
}
122122

123+
/** Override pool options that would otherwise kill sessions or leak windows. */
124+
function isolatePoolSession(): void {
125+
const opts: [string, string][] = [
126+
["destroy-unattached", "off"],
127+
["remain-on-exit", "off"],
128+
];
129+
for (const [key, value] of opts) {
130+
try {
131+
execFileSync("tmux", ["set-option", "-t", POOL, key, value], {
132+
stdio: "ignore",
133+
});
134+
} catch {}
135+
}
136+
try {
137+
execFileSync("tmux", ["set-option", "-t", POOL, "-w", "-g", "remain-on-exit", "off"], {
138+
stdio: "ignore",
139+
});
140+
} catch {}
141+
}
142+
123143
export function spawnAndSwap(command: string, cwd: string, owner: string): string {
124144
const pane = process.env.TMUX_PANE;
125145
if (!pane) throw new Error("not in tmux");
@@ -145,6 +165,7 @@ export function spawnAndSwap(command: string, cwd: string, owner: string): strin
145165
let newPane: string;
146166
if (!poolExists()) {
147167
execFileSync("tmux", ["new-session", "-d", "-s", POOL, "-c", cwd, ...envArg, ...shellArgs]);
168+
isolatePoolSession();
148169
newPane = execFileSync("tmux", ["display-message", "-t", POOL, "-p", "#{pane_id}"], {
149170
encoding: "utf8",
150171
}).trim();

0 commit comments

Comments
 (0)