Last active
February 16, 2026 20:59
-
-
Save michaelsanford/0ff562591a78f6815bb72fc879aead01 to your computer and use it in GitHub Desktop.
My PowerShell 7 $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
| # 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 | |
| # Helpful aliases | |
| function pip { py -m pip $args } | |
| function k { wsl ~/.local/bin/kiro-cli $args } | |
| # Custom shell | |
| # flux-pills.json -> https://gist.github.com/michaelsanford/a8c06cac51da47d03f9d6f0f6d05252f | |
| # Update with | |
| # winget upgrade JanDeDobbeleer.OhMyPosh --source winget | |
| oh-my-posh init pwsh --config ~/.oh/flux-pills.json | Invoke-Expression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment