0

When developing a vscode Extension is it possible to have separate bash scripts inside the code of the Extension which can be executed in the vscode instance where the extension is installed?

Imagine i have .sh scripts beside my extension.ts. When Running the extension i want to be able to open a Terminal per script and execute the scripts.

I can‘t find a way to achieve this

Edit:

My folder structure in the extension repo looks like:

  • scripts/*.sh (multiple scripts)
  • extension.ts

The code I tried:

    let startRuntime = vscode.commands.registerCommand('test.startRuntime', () => {
    const scriptsPath = path.join(__filename, '..', 'scripts');
    const scriptsDir = fs.readdirSync(scriptsPath);

    scriptsDir.forEach((script) => {
        const terminal = vscode.window.createTerminal(`${script}`);
        terminal.show();
        terminal.sendText(`./${script}`);
    });
});

After running the extension a new VSCode instance starts and I want to execute the command. It actually starts as many terminals as i have scripts but in that instance on the terminals i get:

zsh: no such file or directory: ./test.sh

How do e.g other users who use the extension get access to those scripts.

Thank you in advance!

4
  • You don't need any VS Code API for that. Just use the typical Node.js API to call external process (bash in your case) and dispatch the scripts.
    – Lex Li
    Commented Nov 18, 2022 at 22:36
  • Does this answer your question? VSCode Extension that Executes terminal command Commented Nov 19, 2022 at 9:18
  • Hi you two. Thanks for responding, I updated my initial question with the code i tried, maybe this makes my intention more clear. I don't think that your proposals help me to achieve what i want to :(
    – dennis93
    Commented Nov 19, 2022 at 16:34
  • @MikeLischke I want to execute a script which comes from the extensions code (repository) without having this particular script in every vscode workspace where the extension is installed
    – dennis93
    Commented Nov 20, 2022 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.