-
Notifications
You must be signed in to change notification settings - Fork 2
feat: search + open convenience commands #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Tiny cross-platform "open this file in the default app" helper. The command | ||
| // selection is a pure function (unit-testable without spawning anything); the | ||
| // actual spawn lives in the CLI. Used by `deepdive open <id>` to pop the | ||
| // exported HTML report in the user's browser. | ||
|
|
||
| export interface OpenCommand { | ||
| cmd: string; | ||
| args: string[]; | ||
| } | ||
|
|
||
| // Returns the command + args to open `target` with the OS default handler. | ||
| // Every platform uses a DIRECT executable (no shell): the caller passes these | ||
| // straight to spawn() with shell:false, so `target` is a single argv entry and | ||
| // can never be interpreted as a command — no shell-injection surface, even | ||
| // from a user-supplied --out path or session id. | ||
| // | ||
| // Windows deliberately avoids `cmd /c start` (which would route through a | ||
| // shell): `explorer <file>` opens a path with its registered default handler | ||
| // (a browser, for .html) as a plain exec. | ||
| export function browserOpenCommand( | ||
| platform: NodeJS.Platform, | ||
| target: string, | ||
| ): OpenCommand { | ||
| switch (platform) { | ||
| case "win32": | ||
| return { cmd: "explorer.exe", args: [target] }; | ||
| case "darwin": | ||
| return { cmd: "open", args: [target] }; | ||
| default: | ||
| // Linux / BSD — xdg-open is the freedesktop standard. | ||
| return { cmd: "xdg-open", args: [target] }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { browserOpenCommand } from "../dist/open.js"; | ||
|
|
||
| test("browserOpenCommand: macOS uses open", () => { | ||
| assert.deepEqual(browserOpenCommand("darwin", "/tmp/r.html"), { | ||
| cmd: "open", | ||
| args: ["/tmp/r.html"], | ||
| }); | ||
| }); | ||
|
|
||
| test("browserOpenCommand: Windows uses explorer directly (no shell)", () => { | ||
| const c = browserOpenCommand("win32", "C:\\Temp\\r with space.html"); | ||
| assert.equal(c.cmd, "explorer.exe"); | ||
| // Single argv entry, no cmd.exe — the path can't be interpreted as a command. | ||
| assert.deepEqual(c.args, ["C:\\Temp\\r with space.html"]); | ||
| }); | ||
|
|
||
| test("browserOpenCommand: Linux/other uses xdg-open", () => { | ||
| assert.deepEqual(browserOpenCommand("linux", "/tmp/r.html"), { | ||
| cmd: "xdg-open", | ||
| args: ["/tmp/r.html"], | ||
| }); | ||
| assert.equal(browserOpenCommand("freebsd", "/x").cmd, "xdg-open"); | ||
| }); | ||
|
|
||
| test("browserOpenCommand: the target is always the final arg (single argv, no shell)", () => { | ||
| for (const p of ["darwin", "win32", "linux"]) { | ||
| const c = browserOpenCommand(p, "TARGET"); | ||
| assert.equal(c.args[c.args.length - 1], "TARGET"); | ||
| } | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.