Theme | History | KeyBinding
in order to make windows powershell more comfortable and add a zsh-like theme and feature follow me:
-
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. ** if youre usingWindows Terminal:**
- after downloading the font and install it, right click on powershells top bar and go to properties, click on
-
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
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme Powerlevel10k_Classic
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)
}
}