Last active
November 3, 2022 13:56
-
-
Save benoitzohar/ed9ee03bfc5f0861ca1e0fac48af79ac 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
#!/usr/bin/env node | |
// @ts-check | |
// Required parameters: | |
// @raycast.schemaVersion 1 | |
// @raycast.title Open Project in VSCode | |
// @raycast.mode silent | |
// Optional parameters: | |
// @raycast.icon images/vscode.png | |
// @raycast.packageName Open VScode | |
// @raycast.argument1 { "type": "text", "placeholder": "Project Name", "optional": false } | |
// Documentation: | |
// @raycast.description Open selected project in VSCode | |
// @raycast.author Benoit Zohar | |
// @raycast.authorURL https://github.com/benoitzohar | |
const GIT_DIR = "/Users/ben/my/very/real/projects"; // Change this to your projects directory | |
const { readdirSync } = require("fs"); | |
const { resolve } = require("path"); | |
const { exec } = require("child_process"); | |
const projectNamePart = process.argv[2]; | |
if (!projectNamePart) { | |
console.error("Project name is required!"); | |
process.exit(1); | |
} | |
function openProject(path) { | |
exec(`code ${resolve(GIT_DIR, path)}`); | |
} | |
const dirList = readdirSync(GIT_DIR); | |
// if we found the exact project name, open it | |
if (dirList.includes(projectNamePart)) { | |
openProject(projectNamePart); | |
} else { | |
// otherwise fuzzy match | |
dirList.filter((dir) => dir.includes(projectNamePart)).map(openProject); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment