Last active
September 25, 2023 14:51
-
-
Save johnlindquist/30a5b8b07feeb7c0978f46d6f554519e to your computer and use it in GitHub Desktop.
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
// 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