Making VS Code’s Powershell Integrated Console useful

I recently started using VS Code pretty heavily and I’ve had a fun time configuring it – especially getting synth wave glow working! One thing that continued to bother me was the Powershell Integrated Console (PIC) – which is different than a normal terminal running Powershell. Not only was it a different powershell session, but it behaved slightly differently. Let’s take a look at the differences between the two, then look at how to improve the PIC.

Types of Terminals

You can run a number of different terminals inside VS Code. If you don’t see your terminal, you can hit Ctrl-` to bring it up. What kind of terminal comes up is up to you. Pull up settings and search for terminal.integrated.shell.windows. You can check the official docs for more information, including common shells. You’ll note that on that page, it’s called the Integrated Terminal, but don’t confuse that for the Powershell Integrated Console. I’ve chosen Powershell with "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", but whatever you chose, you’ll see it come up as the 1st console:

This is the same terminal no matter what kind of file you are editing. Many of us are editing Powershell, so we also have the Powershell extension installed. This is what gives us intellisense, code snippets, PS Script Analyzer output inline, etc. It also lets us run and debug code, and here’s where the Integrated Terminal and Integrated Console differences start to come into play.

When you highlight a line of code in a Powershell file and hit F8, it runs in your current terminal. In my case, it’s the powershell terminal (#1), as we see here.

When you hit F5, the Powershell extension runs the entire file. In addition to force-saving the file, you’ll notice one big difference – it runs in a different terminal, the Powershell Integrated Console (#2):

That looks a bit different! It’s got a different prompt, it’s got no colors, it’s just not the same. So why does it exist?

When you enable the Powershell extension, it has to run a powershell instance in order to provide the intellisense and syntax highlighting and such. You can hide that terminal on start (in settings.json, add "powershell.integratedConsole.showOnStartup": false), but it HAS to run in order to get those benefits. If you close it (Trashcan icon), you’ll get a notice from the Powershell extension that it crashed and you should restart it, which you need to if you want to leverage the extension (click on Session Exited if you accidentally dismissed the error). So, no, you cannot get rid of the PIC terminal.

It’s still running Powershell, though, right? Except for being a different session, it shouldn’t be a big deal, right? Well, not if you want to do fancy stuff like colors or Ctrl-r to search history or anything involving PSReadline. For reasons that are well beyond the scope of this article, PSReadline support is not available in the Integrated Console from the Powershell extension (issue 535).

Improving the PIC Terminal

Thankfully, there IS a solution! While the PSReadline support is not yet available in the main extension, it IS available in the Powershell Preview extension! This is a preview and you may encounter bugs, but it’s pretty stable for me so far. Just install it through the Extension Manager (Ctrl-Shift-X), disable the Powershell extension, and reload your session. If you modified your theme, you’ll be asked if you want to keep it or revert to the ISE-like theme. You’ll now have access to PSReadline and other preview features. Ctrl-r brings up search history and colors are available, hooray!

If at any time you find the preview extension causes you problems, just go back to the Extension Manager, disable Powershell Preview, Enable Powershell, and reload. Voila!

One other modification I made is to enable emacs mode with PSReadline. This gives you key bindings that mirror emacs, like Ctrl-w to remove a single word, Ctrl-u to delete from the cursor to the beginning of the line, etc. – all things I’m very comfortable with after decades of working in *nix. You can add Set-PSReadLineOption -EditMode Emacs to your profile to enable this – and remember that the Integrated Terminal and the PIC each have their own profile.

You still have to make sure you’re in the right terminal for the right session (variables set in #1 aren’t set in #2, etc.), but hopefully with the Preview extension, you find the Powershell Integrated Console more useful and your overall VS Code experience is improved. Enjoy!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s