Created
October 30, 2020 23:09
-
-
Save alexandair/09e4ec3d90ccc23a6e8eea1bda4f24e9 to your computer and use it in GitHub Desktop.
This file contains 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
$options = @{ | |
AddToHistoryHandler = { | |
param( [string]$line) | |
return $line.Length -gt 3 -and $line[0] -ne ' ' -and $line[0] -ne ';' | |
} | |
} | |
Set-PSReadLineOption @options |
Add-Type
version:
Add-Type -TypeDefinition @'
namespace ProfileUtility
{
public class PSRLUtilities
{
public static object AddToHistoryHandler(string line)
{
return line != null && line.Length > 3 && line[0] != ' ' && line[0] != ';';
}
}
}
'@
$handler = [ProfileUtility.PSRLUtilities].
GetMethod('AddToHistoryHandler').
CreateDelegate([Func[string, object]])
Set-PSReadLineOption -AddToHistoryHandler $handler
Probably slower startup time than the ILAssembler
method, but for sure easier to read.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an example workaround using
ILAssembler
: