Last active
August 9, 2024 04:52
-
-
Save yzraeu/12b96c409ae7da29b1a41ddccec3a0c3 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
| Import-Module posh-git | |
| Import-Module -Name Terminal-Icons | |
| oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\takuya.omp.json" | Invoke-Expression | |
| Import-Module PSReadLine | |
| Import-Module CompletionPredictor | |
| Set-PSReadLineOption -HistorySearchCursorMovesToEnd | |
| Set-PSReadLineOption -PredictionSource HistoryAndPlugin | |
| Set-PSReadLineOption -PredictionViewStyle ListView | |
| Set-PSReadLineOption -EditMode Windows | |
| Set-PSReadLineOption -BellStyle None | |
| Set-PSReadLineOption -Colors @{ InlinePrediction = $PSStyle.Background.Blue } | |
| Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
| Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
| Set-PSReadLineKeyHandler -Key F7 ` | |
| -BriefDescription History ` | |
| -LongDescription 'Show command history' ` | |
| -ScriptBlock { | |
| $pattern = $null | |
| [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$pattern, [ref]$null) | |
| if ($pattern) | |
| { | |
| $pattern = [regex]::Escape($pattern) | |
| } | |
| $history = [System.Collections.ArrayList]@( | |
| $last = '' | |
| $lines = '' | |
| foreach ($line in [System.IO.File]::ReadLines((Get-PSReadLineOption).HistorySavePath)) | |
| { | |
| if ($line.EndsWith('`')) | |
| { | |
| $line = $line.Substring(0, $line.Length - 1) | |
| $lines = if ($lines) | |
| { | |
| "$lines`n$line" | |
| } | |
| else | |
| { | |
| $line | |
| } | |
| continue | |
| } | |
| if ($lines) | |
| { | |
| $line = "$lines`n$line" | |
| $lines = '' | |
| } | |
| if (($line -cne $last) -and (!$pattern -or ($line -match $pattern))) | |
| { | |
| $last = $line | |
| $line | |
| } | |
| } | |
| ) | |
| $history.Reverse() | |
| $command = $history | Out-GridView -Title History -PassThru | |
| if ($command) | |
| { | |
| [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
| [Microsoft.PowerShell.PSConsoleReadLine]::Insert(($command -join "`n")) | |
| } | |
| } | |
| Set-PSReadLineKeyHandler -Key RightArrow ` | |
| -BriefDescription ForwardCharAndAcceptNextSuggestionWord ` | |
| -LongDescription "Move cursor one character to the right in the current editing line and accept the next word in suggestion when it's at the end of current editing line" ` | |
| -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) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment