Created
May 13, 2023 01:03
-
-
Save efrec/48a05c5ed9bf9f2591f41410526b9a41 to your computer and use it in GitHub Desktop.
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
## Command history | |
# Improve on PSReadLine's history heuristic without having to re-implement from scratch. | |
$commandHistoryHandler = @{ | |
HistoryNoDuplicates = $false | |
HistorySaveStyle = [Microsoft.PowerShell.HistorySaveStyle]::SaveIncrementally | |
AddToHistoryHandler = { | |
param([string] $line) | |
<# spammy #> if ($line -in 'exit', 'ls', 'pwd', 'cls', 'clear' ) { return $false } | |
<# buried #> if ($line -match '\A[ ]{2}\S') { return $false } | |
<# assist #> if ($line -match '(?<=^|\b)(?<!\$)(help|get-help|man)(?=\b|$)(?![-:]| *=)') { | |
$sensitive = -not [Microsoft.PowerShell.PSConsoleReadLine]::GetDefaultAddToHistoryOption($line) | |
return $sensitive ? $false : [Microsoft.PowerShell.AddToHistoryOption]::MemoryOnly | |
} | |
<# secret #> if ($line -match 'password|asplaintext|securestring|from-secure|to-secure|key|token') { | |
return [Microsoft.PowerShell.PSConsoleReadLine]::GetDefaultAddToHistoryOption($line) | |
} | |
<# normal #> return [Microsoft.PowerShell.AddToHistoryOption]::MemoryAndFile | |
} | |
} | |
Set-PSReadLineOption @commandHistoryHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment