The PSReadLine plugin in Powershell provides intelligent prompt features based on historical records. Additionally, there are several plugins that provide machine learning-based intelligent prompts. Once all configurations are completed, you can have an IDE-like intelligent prompt experience in Powershell. (The effect in the picture comes from intelligent prompts of historical records and plugins)
It is recommended to install Windows Terminal as the default terminal: Install and get started setting up Windows Terminal
Search for the latest version of PowerShell:
winget search Microsoft.PowerShell
Install PowerShell using the id parameter:
winget install --id Microsoft.Powershell --source winget
Install PSReadLine using PowerShellGet:
Install-Module -Name PSReadLine
Install the Az.Accounts plugin (a prerequisite plugin for the IntelliSense plugin Az.Tools.Predictor):
Install-module -name Az.Accounts -Force
Install the Az.Tools.Predictor plugin:
Install-module -name Az.Tools.Predictor -Force
Enable the Az.Tools.Predictor plugin:
Enable-AzPredictor -AllSession
Install the CompletionPredictor plugin:
Install-Module -Name CompletionPredictor -Repository PSGallery
Open the PowerShell configuration file with Notepad:
notepad $PROFILE
If the above command fails, create a configuration file first:
New-Item -Path $PROFILE -Type File -Force
In the opened configuration file, paste the following configuration content:
# Import intelligent prompt modules
Import-Module PSReadLine
Import-Module Az.Tools.Predictor
Import-Module -Name CompletionPredictor
# Set IntelliSense prediction source and history records and plugins
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Save the configuration file and reload (or restart PowerShell):
. $PROFILE
Now, PowerShell has machine learning-based intelligent prompts. There are two ways to display intelligent prompts, one is inline display, press the right arrow
to select the predicted result when entering. The other is a list prediction view, press the up/down arrow key
to select the predicted result when entering.
Press F2
to switch between inline prediction
and list prediction
modes. If you want PowerShell to automatically switch to list prediction
mode every time it starts, add this sentence to the configuration file:
Set-PSReadLineOption -PredictionViewStyle ListView
The oh-my-posh plugin can provide PowerShell beautification, git information display, and the posh-git plugin can provide intelligent completion of git commands. For example, after installing the posh-git plugin, type git ch
, then press the Tab
key, it will automatically complete as git checkout
, continue to press the Tab
key, it will cycle between commands such as git cherry
and git cherry-pick
.
Install via winget:
winget install JanDeDobbeleer.OhMyPosh -s winget
When using the oh-my-posh plugin, you need to use Nerd Fonts, otherwise, garbled text will appear. The Nerd Fonts website has collected some commonly used Nerd fonts.
You can call up all oh-my-posh themes with this command:
Get-PoshThemes
After selecting your favorite theme (for example, choose the markbull theme), go back to the PowerShell configuration file and add the following content:
# Configure oh-my-posh as an antivirus software exception and select the markbull theme as the default theme
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/markbull.omp.json" | Invoke-Expression
After the configuration is completed, save the configuration file and reload (or restart PowerShell):
. $PROFILE
Install-Module posh-git -Scope CurrentUser -Force
After installation, add the following content to the PowerShell configuration file:
# Import intelligent prompt modules
Import-Module posh-git
Please change the font of the corresponding editor terminal to Nerd Font.
Using Predictors in PSReadLine