Skip to content

Instantly share code, notes, and snippets.

@johnlindquist
Last active September 25, 2023 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnlindquist/30a5b8b07feeb7c0978f46d6f554519e to your computer and use it in GitHub Desktop.
Save johnlindquist/30a5b8b07feeb7c0978f46d6f554519e to your computer and use it in GitHub Desktop.
// Name: Actions Example
import { Action } from "@johnlindquist/kit"
/*
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(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment