Created
January 18, 2026 02:58
-
-
Save michaelsanford/a8c06cac51da47d03f9d6f0f6d05252f to your computer and use it in GitHub Desktop.
Powershell $profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # PSReadLine configuration | |
| # - Visual styling | |
| # - Bash/zsh-style editing chords | |
| # - History-based prediction tuning | |
| # Guard: do nothing if PSReadLine is unavailable (e.g., non-interactive hosts) | |
| if (-not (Get-Module -ListAvailable -Name PSReadLine)) { return } | |
| # Base options: prompt + colours | |
| $PSROptions = @{ | |
| ContinuationPrompt = ' ' # Shown for wrapped / continued lines | |
| Colors = @{ | |
| Operator = $PSStyle.Foreground.Magenta | |
| Parameter = $PSStyle.Foreground.Magenta | |
| Selection = $PSStyle.Background.BrightBlack | |
| InLinePrediction = $PSStyle.Foreground.BrightYellow + $PSStyle.Background.BrightBlack | |
| } | |
| # Prediction and history behaviour | |
| PredictionSource = 'History' # Use command history for suggestions | |
| PredictionViewStyle = 'ListView' # Show suggestions as a list | |
| HistoryNoDuplicates = $true # Avoid duplicating identical commands | |
| MaximumHistoryCount = 50000 # Retain up to 50 000 history entries | |
| } | |
| Set-PSReadLineOption @PSROptions | |
| # Key bindings (bash/zsh-like) | |
| # Ctrl+F: forward one word (note: default is usually "forward character") | |
| Set-PSReadLineKeyHandler -Chord 'Ctrl+f' -Function ForwardWord | |
| # Ctrl+W: delete the word to the left of the cursor | |
| Set-PSReadLineKeyHandler -Chord 'Ctrl+w' -Function BackwardKillWord | |
| # Alt+D: delete the word to the right of the cursor | |
| Set-PSReadLineKeyHandler -Chord 'Alt+d' -Function KillWord | |
| # Ctrl+U: delete from cursor to beginning of the line (bash/zsh kill-line-left) | |
| Set-PSReadLineKeyHandler -Chord 'Ctrl+u' -Function BackwardDeleteLine | |
| # Ctrl+D: if line is empty, run "exit"; otherwise delete character under cursor | |
| Set-PSReadLineKeyHandler -Chord 'Ctrl+d' -ScriptBlock { | |
| $line = $null | |
| $cursor = 0 | |
| [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) | |
| if ([string]::IsNullOrEmpty($line)) { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert('exit') | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } else { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::DeleteChar() | |
| } | |
| } | |
| # Enter: validate syntax then accept the line (prevents executing incomplete input) | |
| Set-PSReadLineKeyHandler -Chord 'Enter' -Function ValidateAndAcceptLine | |
| # Custom shell | |
| # Update with | |
| # winget upgrade JanDeDobbeleer.OhMyPosh --source winget | |
| oh-my-posh init pwsh --config 'https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/refs/heads/main/themes/rudolfs-light.omp.json' | Invoke-Expression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment