@kud/foxhop-cli 1.1.0 → 1.1.2

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.
Files changed (2) hide show
  1. package/dist/cli.js +60 -25
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -289,6 +289,20 @@ var clearScripts = (dir = defaultScriptsDir()) => {
289
289
 
290
290
  // src/cli.ts
291
291
  import { fileURLToPath as fileURLToPath2 } from "url";
292
+
293
+ // src/ui.ts
294
+ var enabled = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
295
+ var paint = (code) => (text) => enabled ? `\x1B[${code}m${text}\x1B[0m` : text;
296
+ var bold = paint(1);
297
+ var dim = paint(2);
298
+ var red = paint(31);
299
+ var green = paint(32);
300
+ var yellow = paint(33);
301
+ var cyan = paint(36);
302
+ var ok = (message) => `${green("\u2713")} ${message}`;
303
+ var fail = (message) => `${red("\u2717")} ${message}`;
304
+
305
+ // src/cli.ts
292
306
  var browserApp = () => process.env.FOXHOP_BROWSER ?? "Firefox Nightly";
293
307
  var runOpen = (args) => {
294
308
  const child = spawn("/usr/bin/open", args, {
@@ -341,7 +355,9 @@ var focus = defineCommand({
341
355
  } : resolveNamed(String(args.name ?? ""));
342
356
  if (!request) {
343
357
  console.error(
344
- `foxhop: no target named "${args.name}". Edit ${CONFIG_PATH}, or run \`foxhop list\` / \`foxhop init\`.`
358
+ fail(
359
+ `no target named "${args.name}". Edit ${CONFIG_PATH}, or run \`foxhop list\` / \`foxhop init\`.`
360
+ )
345
361
  );
346
362
  process.exit(1);
347
363
  }
@@ -349,15 +365,15 @@ var focus = defineCommand({
349
365
  const ack = await sendToHost(request);
350
366
  if (ack?.ok && ack.action !== "not-found") foreground();
351
367
  else
352
- console.error(
353
- `foxhop: ${ack?.error ?? "no matching tab and no url to open"}`
354
- );
368
+ console.error(fail(ack?.error ?? "no matching tab and no url to open"));
355
369
  } catch {
356
370
  if ("url" in request && request.url) {
357
371
  openUrl(request.url);
358
372
  } else {
359
373
  console.error(
360
- "foxhop: cannot reach the host \u2014 is Firefox running with the foxhop extension?"
374
+ fail(
375
+ "cannot reach the host \u2014 is Firefox running with the foxhop extension?"
376
+ )
361
377
  );
362
378
  process.exit(1);
363
379
  }
@@ -386,7 +402,9 @@ var list = defineCommand({
386
402
  }
387
403
  if (!targets.length) {
388
404
  console.log(
389
- `No targets yet. Run \`foxhop init\` for an example, or edit ${CONFIG_PATH}.`
405
+ dim(
406
+ `No targets yet. Run \`foxhop init\` for an example, or edit ${CONFIG_PATH}.`
407
+ )
390
408
  );
391
409
  return;
392
410
  }
@@ -394,9 +412,12 @@ var list = defineCommand({
394
412
  ...targets.filter((target) => target.favorite),
395
413
  ...targets.filter((target) => !target.favorite)
396
414
  ];
415
+ const width = Math.max(...ordered.map((target) => target.name.length));
397
416
  for (const target of ordered) {
398
- const star = target.favorite ? "\u2605 " : " ";
399
- console.log(`${star}${target.name.padEnd(16)} ${target.match}`);
417
+ const star = target.favorite ? yellow("\u2605") : " ";
418
+ console.log(
419
+ `${star} ${cyan(target.name.padEnd(width))} ${dim(target.match)}`
420
+ );
400
421
  }
401
422
  }
402
423
  });
@@ -412,13 +433,13 @@ var tabs = defineCommand({
412
433
  }
413
434
  if (!openTabs.length) {
414
435
  console.error(
415
- "foxhop: no tabs (is Firefox running with the foxhop extension?)"
436
+ fail("no tabs \u2014 is Firefox running with the foxhop extension?")
416
437
  );
417
438
  process.exit(1);
418
439
  }
419
440
  for (const tab of openTabs) {
420
- console.log(`${tab.title}
421
- ${tab.url}`);
441
+ console.log(`${bold(tab.title)}
442
+ ${dim(tab.url)}`);
422
443
  }
423
444
  }
424
445
  });
@@ -429,7 +450,7 @@ var init = defineCommand({
429
450
  },
430
451
  run: () => {
431
452
  const path = writeExampleConfig();
432
- console.log(`foxhop: wrote example config and schema next to ${path}`);
453
+ console.log(ok(`wrote example config + schema \u2192 ${dim(path)}`));
433
454
  }
434
455
  });
435
456
  var installCommand = defineCommand({
@@ -463,7 +484,9 @@ var syncCommand = defineCommand({
463
484
  return;
464
485
  }
465
486
  console.log(
466
- `foxhop: removed ${cleared.removed} script(s) from ${cleared.dir}`
487
+ ok(
488
+ `removed ${bold(String(cleared.removed))} script(s) \u2192 ${dim(cleared.dir)}`
489
+ )
467
490
  );
468
491
  return;
469
492
  }
@@ -477,10 +500,14 @@ var syncCommand = defineCommand({
477
500
  return;
478
501
  }
479
502
  console.log(
480
- `foxhop: wrote ${result.written} script(s)` + (result.removed ? `, removed ${result.removed} stale` : "") + ` in ${result.dir}`
503
+ ok(
504
+ `wrote ${bold(String(result.written))} script(s)` + (result.removed ? `, removed ${result.removed} stale` : "") + ` \u2192 ${dim(result.dir)}`
505
+ )
481
506
  );
482
507
  console.log(
483
- "Add that folder in Raycast \u2192 Extensions \u2192 Script Commands \u2192 Add Directories, then assign hotkeys."
508
+ dim(
509
+ "Add that folder in Raycast \u2192 Extensions \u2192 Script Commands \u2192 Add Directories, then assign hotkeys."
510
+ )
484
511
  );
485
512
  }
486
513
  });
@@ -492,8 +519,8 @@ var add = defineCommand({
492
519
  args: {
493
520
  url: {
494
521
  type: "positional",
495
- required: true,
496
- description: "URL of the tab (e.g. https://gemini.google.com)"
522
+ required: false,
523
+ description: "URL of the tab (e.g. https://gemini.google.com) \u2014 or use --match"
497
524
  },
498
525
  name: {
499
526
  type: "string",
@@ -515,20 +542,26 @@ var add = defineCommand({
515
542
  favorite: { type: "boolean", description: "Pin to the top of the list" }
516
543
  },
517
544
  run: ({ args }) => {
518
- const url = String(args.url);
519
- const derived = deriveTarget(url);
545
+ const url = args.url ? String(args.url) : void 0;
546
+ const matchArg = args.match ? String(args.match) : void 0;
547
+ const source = url ?? matchArg;
548
+ if (!source) {
549
+ console.error(fail("provide a URL or --match"));
550
+ process.exit(1);
551
+ }
552
+ const derived = deriveTarget(source);
520
553
  const name = args.name ?? derived.name;
521
554
  const existing = findTarget(readConfig(), name);
522
555
  upsertTarget({
523
556
  name,
524
- match: args.match ?? derived.match,
557
+ match: matchArg ?? derived.match,
525
558
  url,
526
559
  title: args.title ?? derived.title,
527
560
  strategy: args.strategy,
528
561
  pick: args.pick,
529
562
  favorite: args.favorite || existing?.favorite ? true : void 0
530
563
  });
531
- console.log(`foxhop: saved "${name}"`);
564
+ console.log(ok(`saved ${bold(name)}`));
532
565
  autoSync();
533
566
  }
534
567
  });
@@ -544,10 +577,10 @@ var remove = defineCommand({
544
577
  run: ({ args }) => {
545
578
  const { removed } = removeTarget(String(args.name));
546
579
  if (!removed) {
547
- console.error(`foxhop: no target named "${args.name}"`);
580
+ console.error(fail(`no target named "${args.name}"`));
548
581
  process.exit(1);
549
582
  }
550
- console.log(`foxhop: removed "${args.name}"`);
583
+ console.log(ok(`removed ${bold(String(args.name))}`));
551
584
  autoSync();
552
585
  }
553
586
  });
@@ -566,11 +599,13 @@ var fav = defineCommand({
566
599
  run: ({ args }) => {
567
600
  const { favorite, found } = toggleFavorite(String(args.name));
568
601
  if (!found) {
569
- console.error(`foxhop: no target named "${args.name}"`);
602
+ console.error(fail(`no target named "${args.name}"`));
570
603
  process.exit(1);
571
604
  }
572
605
  console.log(
573
- `foxhop: "${args.name}" ${favorite ? "favourited \u2605" : "unfavourited"}`
606
+ ok(
607
+ `${bold(String(args.name))} ${favorite ? yellow("favourited \u2605") : "unfavourited"}`
608
+ )
574
609
  );
575
610
  }
576
611
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/foxhop-cli",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "foxhop CLI and native messaging host — focus specific Firefox tabs from macOS",
5
5
  "type": "module",
6
6
  "license": "MIT",