VS Code (Windows 10)
What I want to achieve from ps1 script :
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 ?
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.
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 .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With