Skip to content

Instantly share code, notes, and snippets.

@johnlindquist
Created June 12, 2024 05:46
Show Gist options
  • Save johnlindquist/0bb1bb9db9a04471de42e9a7d28786e7 to your computer and use it in GitHub Desktop.
Save johnlindquist/0bb1bb9db9a04471de42e9a7d28786e7 to your computer and use it in GitHub Desktop.
// Name: Actions Example
import { Action } from "@johnlindquist/kit"
import { } from "express"
import { } from "lodash-es"
// Using a "flag" determines where to do to custom logic: After the prompt or in the action
// Also, "flags" are supported when running the script in the terminal with `--js`
let actions: Action[] = [
{
shortcut: `${cmd}+t`,
name: "Append .ts",
visible: true, // Display shortcut in the prompt
onAction: async (input, state) => {
// Since we're not using a "flag", we can do custom logic here
submit(`${state.focused?.name}.ts`)
},
},
{
name: "Append .js",
flag: "js", // Set `global.flag.js` to true when selecting the action
},
]
let result = await arg("Pick a number", ["one", "two", "three"], actions)
if (flag.js) {
result = `${result}.js`
}
await div({ html: result, preview: ``, flags: {} })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment