Search posts, tags, users, and pages
It's a simple script that helps to launch VSCode and Terminal at the provided path. I have to just type node project.js const { exec } = require('child_process'); const fullpath = '/desire/path'; main(); function main() { launchVSCodeAt(fullpath...
saud chougle
@chouglesaud · India
Learner, Software Developer, Freelancer
I am a software engineer who learns and build projects.
Markdown supported · ⌘↵ to post
DoyinSoft Technologies
chougle saud So I decided to enhance the codes making it possible to type in the desired path upon execution of the script:
you can find the new script below
const { exec } = require("child_process"); const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); var fp = ""; rl.question("Enter a Valid Path to Open: ", function (p) { fp = p; main(); rl.close(); }); function main() { launchVSCodeAt(fp); launchTerminalAt(fp); } function launchVSCodeAt(path) { exec(`cd ${path} && code .`, (err) => { if (err) console.log(`failed to launch VSCode at ${path}`); console.log(`VSCode launched at ${path}`); }); } function launchTerminalAt(path) { exec(`cd ${path} && start cmd`, (error) => { if (error) console.log(`failed to launch Terminal at ${path}`); console.log(`Terminal launched at ${path}`); }); }
intresting. i will definitely try out. one catch how will we remember path 🤔.
Always copy paths from the window explorer text box chougle saud
Joshua Alexander
Thanks chougle saud, I'm definitely trying this out tomorrow
Alexander Joshua 👍
hi, You can set multiple paths. or conditions according to your needs. I would love to see if you make it more interesting.
Edidiong Asikpo (Didi)
Welcome to Hashnode, chougle saud. This is an interesting script; I will definitely try it out.
Edidiong Asikpo thanks.
DoyinSoft Technologies
chougle saud So I decided to enhance the codes making it possible to type in the desired path upon execution of the script:
you can find the new script below
const { exec } = require("child_process"); const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); var fp = ""; rl.question("Enter a Valid Path to Open: ", function (p) { fp = p; main(); rl.close(); }); function main() { launchVSCodeAt(fp); launchTerminalAt(fp); } function launchVSCodeAt(path) { exec(`cd ${path} && code .`, (err) => { if (err) console.log(`failed to launch VSCode at ${path}`); console.log(`VSCode launched at ${path}`); }); } function launchTerminalAt(path) { exec(`cd ${path} && start cmd`, (error) => { if (error) console.log(`failed to launch Terminal at ${path}`); console.log(`Terminal launched at ${path}`); }); }