github-search-cli 0.7.0 → 0.8.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/src/share.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Share repo — copy formatted snippets to clipboard.
3
3
  */
4
- import type { Repo } from "./types.ts";
4
+ import type { Repo } from "./types";
5
5
 
6
6
  export type ShareFormat = "markdown" | "plain" | "gh-cli" | "short";
7
7
 
@@ -19,31 +19,36 @@ export function formatShare(repo: Repo, format: ShareFormat): string {
19
19
  }
20
20
 
21
21
  /** Copy text to clipboard via platform command. */
22
+ import { spawn } from "child_process";
23
+
22
24
  export async function copyToClipboard(text: string): Promise<boolean> {
23
25
  try {
24
26
  const p = process.platform;
25
- if (p === "win32") {
26
- const proc = Bun.spawn(["clip"], { stdin: "pipe" });
27
- proc.stdin.write(text);
28
- proc.stdin.end();
29
- await proc.exited;
30
- } else if (p === "darwin") {
31
- const proc = Bun.spawn(["pbcopy"], { stdin: "pipe" });
32
- proc.stdin.write(text);
33
- proc.stdin.end();
34
- await proc.exited;
35
- } else {
36
- // Linux — try xclip, then wl-copy
37
- const cmd = Bun.which("xclip") ? ["xclip", "-selection", "clipboard"] :
38
- Bun.which("wl-copy") ? ["wl-copy"] : null;
39
- if (!cmd) return false;
40
- const proc = Bun.spawn(cmd, { stdin: "pipe" });
41
- proc.stdin.write(text);
42
- proc.stdin.end();
43
- await proc.exited;
44
- }
45
- return true;
27
+ const cmd = p === "win32" ? ["clip"] : p === "darwin" ? ["pbcopy"] : await findLinuxClipCmd();
28
+ if (!cmd) return false;
29
+ const proc = spawn(cmd[0], cmd.slice(1), { stdio: ["pipe", "ignore", "ignore"] });
30
+ proc.stdin.write(text);
31
+ proc.stdin.end();
32
+ return new Promise((resolve) => {
33
+ proc.on("close", (code) => resolve(code === 0));
34
+ proc.on("error", () => resolve(false));
35
+ });
46
36
  } catch {
47
37
  return false;
48
38
  }
49
39
  }
40
+
41
+ async function findLinuxClipboard(): Promise<string[] | null> {
42
+ const { execFileSync } = await import("child_process");
43
+ try {
44
+ execFileSync("xclip", ["-version"], { stdio: "ignore" });
45
+ return ["xclip", "-selection", "clipboard"];
46
+ } catch {
47
+ try {
48
+ execFileSync("wl-copy", ["--version"], { stdio: "ignore" });
49
+ return ["wl-copy"];
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+ }
package/src/trending.ts CHANGED
@@ -1,12 +1,5 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * trending.ts — "Trending Repositories" view for the GitHub repo browser CLI.
4
- *
5
- * Polished terminal UI built with OpenTUI. Tokyo Night palette.
6
- *
7
- * Run directly: bun run src/trending.ts
8
- * Or import: import { launchTrending } from "./trending.ts";
9
- */
1
+ #!/usr/bin/env node
2
+ /** trending.ts — "Trending Repositories" view for the GitHub repo browser CLI. */
10
3
  import {
11
4
  createCliRenderer,
12
5
  BoxRenderable,
@@ -18,10 +11,10 @@ import {
18
11
  dim,
19
12
  t,
20
13
  } from "@opentui/core";
21
- import type { Repo } from "./types.ts";
22
- import { openUrl } from "./open-url.ts";
23
- import { NetworkError } from "./errors.ts";
24
- import type { GitHubSearchEnvelope } from "./normalizer.ts";
14
+ import type { Repo } from "./types";
15
+ import { openUrl } from "./open-url";
16
+ import { NetworkError } from "./errors";
17
+ import type { GitHubSearchEnvelope } from "./search";
25
18
 
26
19
  // ─── Tokyo Night palette ──────────────────────────────────────────────
27
20
  const C = {
@@ -130,7 +123,7 @@ export async function fetchTrendingRepos(since: "daily" | "weekly" | "monthly"):
130
123
  res = await fetch(url, {
131
124
  headers: {
132
125
  Accept: "application/vnd.github+json",
133
- "User-Agent": "search-cli",
126
+ "User-Agent": "ghfind",
134
127
  },
135
128
  });
136
129
  } catch {
@@ -559,6 +552,8 @@ export async function launchTrending(): Promise<void> {
559
552
  }
560
553
 
561
554
  // ── Auto-run ──────────────────────────────────────────────────────────
562
- if (import.meta.main) {
555
+ // Only launch when run directly (bun run src/trending.ts), not when bundled
556
+ // into cli.js or imported as a module.
557
+ if (import.meta.main && !process.env.GHFIND_BUNDLED) {
563
558
  launchTrending();
564
559
  }