Created
December 5, 2021 17:09
-
-
Save dnicolson/504a4f16460866a16ac1725cb2aec292 to your computer and use it in GitHub Desktop.
Raycast extension to launch projects in Visual Studio Code
This file contains 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
import { ActionPanel, showToast, ToastStyle, List, closeMainWindow } from "@raycast/api"; | |
import fs from "fs"; | |
import path from "path"; | |
import { exec } from "child_process"; | |
import untildify from "untildify"; | |
type directories = { | |
[key: string]: string; | |
}; | |
export default function () { | |
const directories = { | |
"~/Work/OpenSource": "Open Source", | |
} as directories; | |
return ( | |
<List searchBarPlaceholder="Search for project…"> | |
{Object.keys(directories).map((directory) => ( | |
<List.Section key={directory} title={directories[directory]}> | |
{fs | |
.readdirSync(untildify(directory), { | |
withFileTypes: true, | |
}) | |
.filter((project) => project.isDirectory()) | |
.map((project) => project.name) | |
.map((projectName) => { | |
const projectDirectory = untildify(path.join(directory, projectName)); | |
const icon = { fileIcon: projectDirectory }; | |
return ( | |
<List.Item | |
key={projectName} | |
icon={icon} | |
title={projectName} | |
actions={ | |
<ActionPanel> | |
<ActionPanel.Item | |
title="Open in Code" | |
onAction={async () => { | |
exec(`open -a 'Visual Studio Code' "${projectDirectory}"`, (err) => err && showToast(ToastStyle.Failure, err?.message)); | |
await closeMainWindow({ clearRootSearch: true }); | |
}} | |
/> | |
</ActionPanel> | |
} | |
/> | |
); | |
})} | |
</List.Section> | |
))} | |
</List> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment