Skip to content

Instantly share code, notes, and snippets.

@benoitzohar
Last active November 3, 2022 13:56
Show Gist options
  • Save benoitzohar/ed9ee03bfc5f0861ca1e0fac48af79ac to your computer and use it in GitHub Desktop.
Save benoitzohar/ed9ee03bfc5f0861ca1e0fac48af79ac to your computer and use it in GitHub Desktop.
#!/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