Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Open new terminal from powershell

VS Code (Windows 10)

What I want to achieve from ps1 script :

  • open 4 terminal tabs
  • first one run python venv and then run django server
  • second one run python venv and then run django shell
  • third one run react (yarn start)
  • fourth normal powershell for git and other

I created a powershell script that I run from default opened terminal. Now I'd like to open a new terminal tab from first one.

Can I fire a vs code command shortcut (Ctrl+`) or a vs code command palette (Ctrl+Shift+P) from terminal ?

like image 530
Yvain Avatar asked Jun 22 '18 07:06

Yvain


People also ask

How do I open Visual Studio code in PowerShell terminal?

The PowerShell terminal is the default terminal on Windows. You can open a terminal by pressing Ctrl+` . Once the terminal is open, you can run PowerShell commands by typing them in the terminal pressing enter.

How do I open VS Code in terminal windows?

One way of opening your terminal is hitting the command button and the spacebar at the same time. This opens spotlight search. From here, you can type "terminal". Once your terminal is open, you can open VS Code from it by typing $ code .

How do I switch between VS Code terminals?

Once the cursor is in the terminal section you can use ctrl+x ctrl+up or ctrl+x ctrl+down to cycle through the active terminals (note that moving between on-screen split terminals is done with ctrl+x left or ctrl+x right ). cmd-J is still used to hide/show the terminal pane.


1 Answers

Here is how I solved my problem.

I created a VS Code extension and I used the extension API.

// Create a terminal Window
const term = vscode.window.createTerminal("terminal_name");

// Write any powershell command
term.sendText("cd C:\\path\\to\\follow\\");

// Any other command
term.sendText("yarn start");

// Create a second terminal
const secTerm = vscode.window.createTerminal("second_terminal_name");

secTerm.sendText("cd C:\\another\\path\\to\\follow\\");

secTerm.sendText("py manage.py runserver");

// and so one
like image 195
Yvain Avatar answered Oct 01 '22 00:10

Yvain