Skip to content

Commit 99eaec1

Browse files
author
Ubuntu
committed
refactor: use open package for browser operations
Replaces platform-specific browser opening (exec with xdg-open/start/open) with the cross-platform 'open' npm package. Closes #16
1 parent b7f6eec commit 99eaec1

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/commands/document.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { exec } from "node:child_process";
21
import { readFileSync } from "node:fs";
32
import chalk from "chalk";
43
import type { Command } from "commander";
4+
import open from "open";
55
import { apiRequest } from "../lib/api.js";
66
import { getBaseUrl } from "../lib/auth.js";
77
import { renderMarkdown } from "../lib/markdown.js";
@@ -59,16 +59,6 @@ function readTextInput(opts: {
5959
return opts.text;
6060
}
6161

62-
function openInBrowser(url: string): void {
63-
const cmd =
64-
process.platform === "win32"
65-
? `start "" "${url}"`
66-
: process.platform === "darwin"
67-
? `open "${url}"`
68-
: `xdg-open "${url}"`;
69-
exec(cmd);
70-
}
71-
7262
function extractTitleFromText(text: string): { title?: string; body: string } {
7363
const lines = text.split("\n");
7464
const firstLine = lines[0]?.trim();
@@ -161,7 +151,7 @@ export function registerDocumentCommand(program: Command): void {
161151
.action(async (id: string) => {
162152
const resolved = await resolveDocumentRef(id);
163153
const fullUrl = `${getBaseUrl()}${resolved.url}`;
164-
openInBrowser(fullUrl);
154+
await open(fullUrl);
165155
console.log(chalk.dim(`Opened: ${fullUrl}`));
166156
});
167157

0 commit comments

Comments
 (0)