Setting up PowerShell environment
Windows 11
Windows 11 comes with Windows Terminal pre-installed.
Once you install the latest PowerShell, you will automatically have Cascadia Code Mono and PSReadLine and don't need to do any additional work.
winget install JanDeDobbeleer.OhMyPosh -s winget
Open an Admin powershell and run:
oh-my-posh font install
Choose Cascadia Code and it will download and install CaskaydiaCove NerdFont.
Open Windows Terminal settings
Rendering > Set Use the new text renderer (“AtlasEngine”) to On Profiles > Defaults > Appearance then Turn on Retro terminal effects and change the Background image and settings if you wish. Profiles > Defaults > Appearance set font to CaskaydiaCove NerdFont Mono
For the profiles you don't want, choose Hide profile from dropdown
.
Open your Powershell profile with code $profile
oh-my-posh init pwsh | Invoke-Expression
Restart Windows Terminal, or reload your profile with . $profile
oh-my-posh debug
to view diagnostics of Oh My Posh if you think it or its themes are slowing down your prompt.
Terminal: Windows Terminal
Install from Windows Store (auto-updating) or:
winget install --id=Microsoft.WindowsTerminal -e
Shell: PowerShell Core
- Install latest stable PowerShell Core from https://github.com/PowerShell/PowerShell/releases/latest
- Configure PowerShell Core as your default shell in Windows Terminal by going to
Settings
or hittingctrl+,
and ensure the default profile GUID matches the PowerShell GUID (not the Windows PowerShell GUID)
Font: Cascadia Code
This is a new monospaced font from Microsoft developed for Windows Terminal, to be used for command-line apps and text editors.
If you have Windows 11 or Visual Studio 2022, Cascadia Code will be installed, but you may still want to download the latest full release which includes Powerline and ligatures
- Download latest release from https://github.com/microsoft/cascadia-code/releases
- Extract the zip, right click the TTF files and choose Install for all users
- Recommended: Cascadia Code PL (includes ligatures, and Powerline symbols)
Set this in your Windows Terminal settings e.g.
"profiles":
[
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
"name": "PowerShell",
"source": "Windows.Terminal.PowerShellCore",
"fontFace": "Cascadia Code PL"
}
],
Visual Studio Code (VSCode)
In File
> Preferences
> Settings
, search for terminal font
and set Terminal
> Integrated:
Font Family
to Cascadia Code PL
Visual Studio
- Open
Tools
>Options
Environment
>Font and Colors
- Under the
Show settings for:
dropdown, selectTerminal
- Set the
Font
toCascadia Code PL
PSReadLine
Install the official improved PowerShell command-line editing
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
Add to your $profile
:
if ($host.Name -eq 'ConsoleHost')
{
Import-Module PSReadLine
}
Updating PSReadLine
If you need to update PSReadLine, you should close down all open PowerShell sessions and run from Win+R
:
pwsh.exe -noprofile -command "Install-Module PSReadLine -Force -SkipPublisherCheck -AllowPrerelease"
PowerShell theming: Oh-My-Posh
- Install Oh-My-Posh for console theming and coloured indicators
- Install Posh-Git for git status indicators
winget install JanDeDobbeleer.OhMyPosh -s winget
Install-Module posh-git -Scope CurrentUser -Force
Install-Module oh-my-posh -Scope CurrentUser -Force
or to update:
Update-Module posh-git
Update-Module oh-my-posh
Add to your $profile
:
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme paradox
Themes other than Paradox can be seen at https://github.com/JanDeDobbeleer/oh-my-posh#themes
Auto-completion
dotnet
Enable dotnet auto-completion by adding the following to your $profile
:
# PowerShell parameter completion shim for the dotnet CLI
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
WinGet
Add WinGet auto-completion by adding the following to your $profile
:
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
$Local:word = $wordToComplete.Replace('"', '""')
$Local:ast = $commandAst.ToString().Replace('"', '""')
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}