Skip to content

Instantly share code, notes, and snippets.

@manzt
Created September 13, 2022 21:21
Show Gist options
  • Save manzt/f9237c75de73e3ce51f815983cf801a9 to your computer and use it in GitHub Desktop.
Save manzt/f9237c75de73e3ce51f815983cf801a9 to your computer and use it in GitHub Desktop.
import { Command } from "https://deno.land/x/cliffy@v0.25.0/command/mod.ts";
import { open } from "https://deno.land/x/open@v0.0.5/index.ts";
let subcmds = [
"search",
"images",
"shopping",
"news",
"videos",
"maps",
"books",
"flights",
];
async function google(search: string, subcommand: typeof subcmds[number]) {
await open(
`https://google.com/${subcommand}?q=${encodeURIComponent(search)}`,
);
}
let cmd = new Command()
.name("google")
.version("0.0.0")
.description("An alias to launch Google via the command line")
.arguments("<search>")
.action((_, search) => google(search, "search"))
.global();
for (let subcmd of subcmds) {
cmd.command(
subcmd,
new Command()
.description(`Search within "${subcmd}"`)
.arguments("<search>")
.action((_, search) => google(search, subcmd)),
);
}
await cmd.parse(Deno.args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment