internal/keybindings/addToHistory.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#region ALT+W : Save current line(s) in history but don't execute
Set-PSReadlineKeyHandler -Chord Alt+w -BriefDescription SaveInHistory -Description "Save current line in history but do not execute" -ScriptBlock {
    
    $line = $null
    
    # Get current line(s) of input
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$null)
    
    # Add them to the command history
    [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($line)
    
    # Clear input line
    [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
}
#endregion ALT+W : Save current line(s) in history but don't execute