Open Project in VSCode Script

As requested by John:

I have my projects in ~/code and temporary projects in ~/Desktop. Sometimes they're in sub-directories as well. Every project has a root-level package.json, so I put together this script to quickly open a project in vscode:

// Menu: Open Project
// Description: Opens a project in code
// Shortcut: cmd shift .
async function getProjects(parentDir) {
const codeDir = await ls(parentDir)
const choices = []
for (const dir of codeDir) {
if (dir.includes('node_modules')) continue
const fullPath = path.join(parentDir, dir)
if (await isFile(path.join(fullPath, 'package.json'))) {
name: dir,
value: fullPath,
description: fullPath,
} else {
choices.push(...(await getProjects(fullPath)))
return choices
const choice = await kitPrompt({
placeholder: 'Which project?',
choices: [
...(await getProjects('~/code')),
...(await getProjects('~/Desktop')),
exec(`code ${choice}`)

Works great!