Skip to content

Instantly share code, notes, and snippets.

@chris-brown
Last active December 21, 2021 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-brown/4f4ba2844b3b7bf867f456aa5c5bc4d5 to your computer and use it in GitHub Desktop.
Save chris-brown/4f4ba2844b3b7bf867f456aa5c5bc4d5 to your computer and use it in GitHub Desktop.
Powershelll Profile
Import-Module posh-git
Import-Module Terminal-Icons
Set-PoshPrompt -Theme C:\Users\*changeme*\.powerline-override.json
# This key handler shows the entire or filtered history using Out-GridView. The
# typed text is used as the substring pattern for filtering. A selected command
# is inserted to the command line without invoking. Multiple command selection
# is supported, e.g. selected by Ctrl + Click.
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"))
}
}
@chris-brown
Copy link
Author

chris-brown commented Dec 21, 2021

To use, install the following;

  • winget install JanDeDobbeleer.OhMyPosh
  • Install-Module -Name Terminal-Icons -Repository PSGallery
  • Install-Module posh-git -Scope CurrentUser
  • Install CaskaydiaCove Nerd Font

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment