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 CHANGED
@@ -64,9 +64,10 @@ s ls
64
64
  s <name>
65
65
  # Example:
66
66
  s work
67
- ```
68
67
 
69
- _Opens a new Windows Terminal window with all configured tabs._
68
+ # Open in current Windows Terminal window: --current or -c
69
+ s work -c
70
+ ```
70
71
 
71
72
  ### 4 Not implemented features
72
73
 
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 args = [];
297
+ const tabArgs = [];
298
298
  tabs.forEach((tab, index) => {
299
299
  if (index > 0) {
300
- args.push(";");
301
- args.push("new-tab");
300
+ tabArgs.push(";");
301
+ tabArgs.push("new-tab");
302
302
  }
303
- args.push("-p");
304
- args.push("Windows PowerShell");
303
+ tabArgs.push("-p");
304
+ tabArgs.push("Windows PowerShell");
305
305
  if (tab.path) {
306
- args.push("-d");
307
- args.push(tab.path);
306
+ tabArgs.push("-d");
307
+ tabArgs.push(tab.path);
308
308
  }
309
309
  if (tab.command) {
310
- args.push("powershell");
311
- args.push("-NoExit");
312
- args.push("-Command");
313
- args.push(tab.command);
310
+ tabArgs.push("powershell");
311
+ tabArgs.push("-NoExit");
312
+ tabArgs.push("-Command");
313
+ tabArgs.push(tab.command);
314
314
  }
315
315
  });
316
- console.log(chalk.blue(`Launching session '${sessionName}'...`));
317
- spawn("wt", args, {
318
- detached: true,
319
- stdio: "ignore",
320
- shell: false
321
- }).unref();
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.0.3");
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtsm",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Windows Terminal Session Manager",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",