wtsm 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/index.mjs +49 -20
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -282,7 +282,7 @@ function listCommand() {
|
|
|
282
282
|
|
|
283
283
|
//#endregion
|
|
284
284
|
//#region src/commands/restore.ts
|
|
285
|
-
function restoreSession(sessionName) {
|
|
285
|
+
function restoreSession(sessionName, options = {}) {
|
|
286
286
|
const sessions = loadSessions();
|
|
287
287
|
if (!sessions[sessionName]) {
|
|
288
288
|
console.log(chalk.red(`Session '${sessionName}' not found.`));
|
|
@@ -294,31 +294,60 @@ function restoreSession(sessionName) {
|
|
|
294
294
|
console.log(chalk.yellow(`Session '${sessionName}' is empty.`));
|
|
295
295
|
return;
|
|
296
296
|
}
|
|
297
|
-
const
|
|
297
|
+
const tabArgs = [];
|
|
298
298
|
tabs.forEach((tab, index) => {
|
|
299
299
|
if (index > 0) {
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
tabArgs.push(";");
|
|
301
|
+
tabArgs.push("new-tab");
|
|
302
302
|
}
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
tabArgs.push("-p");
|
|
304
|
+
tabArgs.push("Windows PowerShell");
|
|
305
305
|
if (tab.path) {
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
tabArgs.push("-d");
|
|
307
|
+
tabArgs.push(tab.path);
|
|
308
308
|
}
|
|
309
309
|
if (tab.command) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
310
|
+
tabArgs.push("powershell");
|
|
311
|
+
tabArgs.push("-NoExit");
|
|
312
|
+
tabArgs.push("-Command");
|
|
313
|
+
tabArgs.push(tab.command);
|
|
314
314
|
}
|
|
315
315
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
316
|
+
const isWindowsTerminal = !!process.env.WT_SESSION;
|
|
317
|
+
const launch = (inCurrentWindow) => {
|
|
318
|
+
const canUseCurrentWindow = inCurrentWindow && isWindowsTerminal;
|
|
319
|
+
const finalArgs = canUseCurrentWindow ? [
|
|
320
|
+
"-w",
|
|
321
|
+
"0",
|
|
322
|
+
...tabArgs
|
|
323
|
+
] : tabArgs;
|
|
324
|
+
if (!canUseCurrentWindow) {
|
|
325
|
+
if (inCurrentWindow && !isWindowsTerminal) console.log(chalk.yellow("Not running in Windows Terminal. Opening in new window..."));
|
|
326
|
+
else console.log(chalk.blue(`Launching session '${sessionName}' in new window...`));
|
|
327
|
+
spawn("wt", finalArgs, {
|
|
328
|
+
detached: true,
|
|
329
|
+
stdio: "ignore",
|
|
330
|
+
shell: false
|
|
331
|
+
}).unref();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
console.log(chalk.blue(`Attempting to launch session '${sessionName}' in current window...`));
|
|
335
|
+
const subprocess = spawn("wt", finalArgs, {
|
|
336
|
+
stdio: "inherit",
|
|
337
|
+
shell: false
|
|
338
|
+
});
|
|
339
|
+
subprocess.on("error", (err) => {
|
|
340
|
+
console.log(chalk.yellow(`Failed to launch in current window. Opening new window...`));
|
|
341
|
+
launch(false);
|
|
342
|
+
});
|
|
343
|
+
subprocess.on("exit", (code) => {
|
|
344
|
+
if (code !== 0) {
|
|
345
|
+
console.log(chalk.yellow(`Could not target current window (exit code ${code}). Opening new window...`));
|
|
346
|
+
launch(false);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
launch(!!options.currentWindow);
|
|
322
351
|
}
|
|
323
352
|
|
|
324
353
|
//#endregion
|
|
@@ -332,7 +361,7 @@ function setupKeypressEvents() {
|
|
|
332
361
|
setupKeypressEvents();
|
|
333
362
|
function createCLI() {
|
|
334
363
|
const program = new Command();
|
|
335
|
-
program.name("s").description("Windows Terminal Session Manager").version("1.
|
|
364
|
+
program.name("s").description("Windows Terminal Session Manager").version("1.1.1");
|
|
336
365
|
program.addCommand(createCommand());
|
|
337
366
|
program.addCommand(addCommand());
|
|
338
367
|
program.addCommand(listCommand());
|
|
@@ -352,7 +381,7 @@ if (rawArgs.length > 0 && ![
|
|
|
352
381
|
].includes(rawArgs[0])) {
|
|
353
382
|
const sessionName = rawArgs[0];
|
|
354
383
|
if (rawArgs[1] === "add") addToSession(sessionName, process.cwd());
|
|
355
|
-
else restoreSession(sessionName);
|
|
384
|
+
else restoreSession(sessionName, { currentWindow: rawArgs.includes("--current") || rawArgs.includes("-c") });
|
|
356
385
|
} else createCLI().parse(process.argv);
|
|
357
386
|
|
|
358
387
|
//#endregion
|