// Preview: docs// Menu: Open Project// Description: Opens a project in vscode// Shortcut: cmd shift .import "@johnlindquist/kit";const envPath = await env('PROJECT_DIR');const projectDir = home(envPath);const projectList = await readdir(projectDir);let { projects, write } = await db("projects", {projects: projectList,})projectList.forEach(async value => {if (!projects.includes(value)) {projects.push(value);await write()}})onTab("Open", async () => {let project = await arg("Open project:", projects.map(project => project.split('\\').pop()))edit('', path.resolve(projectDir, project))})onTab("Add Path", async () => {while (true) {let project = await arg("Add path to project:",md(projects.map(project => `* ${project.split('\\').pop()}`).join("\n")))projects.push(project)await write()}})onTab("Remove", async () => {while (true) {let project = await arg("Open project:", projects.map(project => project.split('\\').pop()))project.split(':').length > 1 ? await rm(path.resolve(project)) : await rm(path.resolve(projectDir, project))let indexOfProject = projects.indexOf(project)projects.splice(indexOfProject, 1)await write()}})onTab("New Project", async () => {while (true) {let project = await arg({placeholder: "Create new project:", debounceInput: 400,enter: "Create", validate: async (input) => {let exists = await isDir(path.resolve(projectDir, input));if (exists) {return `${input} already exists`;}return true;}},)projects.push(project)mkdir(path.resolve(projectDir, project))await write()}})
import "@johnlindquist/kit"// Menu: Search Anime// Description: Use the jikan.moe API to search anime// Author: John Lindquist, Updated by Ambushfalllet anime = await arg("Anime:")let response = await get(`https://api.jikan.moe/v4/anime?q=${anime}`)let { images, title } = response.data.data[0]let { jpg } = imageslet { image_url, small_image_url, large_image_url } = jpgconst html = `<a :href="url"><img :src="url" /><div class="card__name"><span>${title}</span></div></a>`;let wg = await widget(html, {state: {url: large_image_url}})wg.onResized(async () => {wg.fit()})// win32 on-click not working so this does nothing really.// TODO: When on click starts working change state to the next result// wg.onClick((event) => event.targetId === "x" ? wg.close() : inspect(event.targetId));
// Menu: Clipboard History// Description: Copy something from the clipboard history// Shortcut: command shift vimport "@johnlindquist/kit"let { history } = await db("clipboard-history")let { value, type } = await arg("What to paste?", () => {return history.map(({ value, type, timestamp, secret }) => {return {type,name: secret ? value.slice(0, 4).padEnd(10, "*") : value,value: {value,type,},description: timestamp,preview:type === "image"? md(`![timestamp](${value})`): value.includes("\n")? `<div class="font-mono text-xs">${value.split("\n").map((line) => `<p>${line}</p>`).join("")}<div>`: null,}})})if (type === "image") {await copyPathAsImage(value)await keystroke("command v")}if (type === "text") {await setSelectedText(value)}
// Menu: Copy to Clipboard// Description: Save to Clipboard history// Shortcut: command shift cimport "@johnlindquist/kit"let { write, history } = await db("clipboard-history", { history: [{ value: "", type: "", timestamp: "", secret: "" }] })const clipboardVal = await clipboard.readText();const newValue = {value: clipboardVal,timestamp: new Date(Date.now()).toLocaleString('en-GB', { timeZone: 'UTC' }),secret: clipboardVal.includes('secret'),type: /(http)?s?:?(\/\/[^"']*\.(?:png|jpg|jpeg|gif|png|svg))/i.test(clipboardVal) ? "image" : "text"}history.push(newValue)await write()