Theme | History | KeyBinding
in order to make windows powershell more comfortable and add a some theme and features like history binding, auto complete on keypress and so on, if you have used linux teminl wiht zsh for example, we are going to make powershell like that as much as we can.
Git status information:Posh-Gitadds Git status information to your prompt as well as tab-completion for Git commands, parameters, remotes, and branch names.Theme:Oh-My-Poshprovides theme capabilities for your PowerShell prompt. Oh-My-Posh comes with several built-in themes.History and History Based Prediction: Predictive IntelliSense is implemented in the PowerShell engine and presented through the PSReadLine module.Key Bindings for Predictions: Key bindings control cursor movement and additional features within the prediction. When you type a character the prediction suggestes you last command started with typed character(s). by using Up/Down Arrows you can switch between commands with same start-characters.
- Run powershell as an
administratorand execute following command todisable the execution policy, otherwise it wont let you follow next stepsSet-ExecutionPolicy RemoteSignedRegister-PSRepository -Default# this registers the default repository for PowerShell modules, so we can install packages thats are in next stepsInstall-Module posh-git -Scope CurrentUserInstall-Module oh-my-posh -Scope CurrentUserInstall-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck
- Now you need to create a profile to set custom settings for powershell, run the following caommand:
notepad $PROFILE# this would create/edit file as: "C:\Users<YOURUSERNAME>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"- Now copy the following code and past it in the notepad and save the file.
- You may need to install a font that supports the emojis!, I suggest to use Hack Nerd Font Mono
- after downloading the font and install it, right click on powershells top bar and go to properties, click on
Fonttab and select the font.
- after downloading the font and install it, right click on powershells top bar and go to properties, click on
if youre using Windows Terminal:
- open the app, hit
Ctrland,then click on gear button at down-left side, inside the open jason file search for"profiles":, now edit/add"defaults":thefontFaceso that finally sould looks:
...
"profiles":
{
"defaults":
{
"fontFace": "Hack Nerd Font Mono",
...
},
...
...Read more at:
- https://devblogs.microsoft.com/powershell/announcing-psreadline-2-1-with-predictive-intellisense/
- https://docs.microsoft.com/en-us/windows/terminal/tutorials/powerline-setup
It is possible to create your own theme for powershell, in order to do that:
- run
Set-PoshPrompt -Theme jandedobbeleerto set an initial theme, then runexport-PoshTheme -FilePath ~/.oh-my-posh.omp.jsonto export the theme at"C:\Users\<YOURUSERNAME\.oh-my-posh.omp.json". - now open that json file
C:\Users\<YOURUSERNAME\.oh-my-posh.omp.jsonand customize as you want - run
Set-PoshPrompt -Theme C:\Users\<YOURUSERNAME\.oh-my-posh.omp.jsonso your edited theme would be used. - have look at Nerd Fonts, to find more icons
The json file attached is an example, which I've edited for test perpose.
Import-Module posh-git
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\star.omp.json" | Invoke-Expression
Set-PSReadLineOption -PredictionSource History
Set-PSReadlineKeyHandler -Key "Tab" -Function MenuComplete
Set-PSReadlineKeyHandler -Key "UpArrow" -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key "DownArrow" -Function HistorySearchForward
Set-PSReadLineOption -Colors @{ InlinePrediction = '#898c5b'}
Set-PSReadlineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key "RightArrow" -ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
if ($cursor -lt $line.Length) {
[Microsoft.PowerShell.PSConsoleReadLine]::ForwardChar($key, $arg)
} else {
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptNextSuggestionWord($key, $arg)
}
}
Set-PSReadLineKeyHandler -Key End -ScriptBlock {
param($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)
if ($cursor -lt $line.Length) {
[Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine($key, $arg)
} else {
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptSuggestion($key, $arg)
}
}



@Kyu Hi
This gist is an old one, I'm currently using Linux for about +3 years as my main OS and as a result of not using windows anymore I did not use the context of this gist for a long time.
You should look at the official websites and documents of
oh-my-pushandnerd-fontsso to be able to install and configure anything required, also still part of this gist works (as I can remember that we have used for one of my friends) but I'm sorry that due to changes made tooh-my-pushpackage the instruction about it's installation does not work.