-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,118 @@ | ||
#!/usr/bin/env -S deno run -A | ||
|
||
import * as sunbeam from "https://deno.land/x/sunbeam/mod.ts"; | ||
|
||
if (Deno.args.length == 0) { | ||
const manifest: sunbeam.Manifest = { | ||
title: "Tabs", | ||
description: "Manage Browser Tabs", | ||
commands: [ | ||
{ | ||
"name": "list", | ||
"title": "List Tabs", | ||
mode: "filter" | ||
}, | ||
{ | ||
name: "close", | ||
title: "Close tab", | ||
mode: "silent", | ||
params: [ | ||
{ | ||
name: "id", | ||
title: "Tab ID", | ||
type: "number", | ||
required: true | ||
} | ||
] | ||
}, | ||
{ | ||
name: "focus", | ||
title: "Focus tab", | ||
mode: "silent", | ||
params: [ | ||
{ | ||
name: "id", | ||
title: "Tab ID", | ||
type: "number", | ||
required: true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
console.log(JSON.stringify(manifest)); | ||
Deno.exit(0); | ||
} | ||
const payload: sunbeam.Payload = JSON.parse(Deno.args[0]); | ||
|
||
if (payload.command == "list") { | ||
const { stdout, success } = await new Deno.Command("popcorn", { | ||
args: ["tab", "list", "--json"] | ||
}).outputSync(); | ||
|
||
if (!success) { | ||
console.error("Error: Failed to list tabs"); | ||
Deno.exit(1); | ||
} | ||
|
||
const tabs = JSON.parse(new TextDecoder().decode(stdout)); | ||
const list: sunbeam.List = { | ||
items: tabs.map((tab: any) => ({ | ||
title: tab.title || "Untitled", | ||
subtitle: tab.url || "", | ||
actions: [ | ||
{ | ||
type: "run", | ||
title: "Focus Tab", | ||
exit: true, | ||
command: "focus", | ||
params: { | ||
id: tab.id | ||
} | ||
}, | ||
{ | ||
type: "copy", | ||
title: "Copy URL", | ||
text: tab.url, | ||
exit: true | ||
}, | ||
{ | ||
type: "run", | ||
title: "Close Tab", | ||
command: "close", | ||
reload: true, | ||
params: { | ||
id: tab.id | ||
} | ||
} | ||
] | ||
})) | ||
} | ||
|
||
console.log(JSON.stringify(list)); | ||
} else if (payload.command == "close") { | ||
const tabID = payload.params["id"] as number; | ||
|
||
const { success } = await new Deno.Command("popcorn", { | ||
args: ["tab", "close", tabID.toString()] | ||
}).output(); | ||
|
||
if (!success) { | ||
console.error("Error: Failed to close tab"); | ||
Deno.exit(1); | ||
} | ||
} else if (payload.command == "focus") { | ||
const tabID = payload.params["id"] as number; | ||
|
||
const { success } = await new Deno.Command("popcorn", { | ||
args: ["tab", "focus", tabID.toString()] | ||
}).output(); | ||
|
||
if (!success) { | ||
console.error("Error: Failed to focus tab"); | ||
Deno.exit(1); | ||
} | ||
} | ||
|
||
|
||
|
This file contains 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