Skip to content

Instantly share code, notes, and snippets.

@tahir-hassan
Last active September 8, 2021 00:18
Show Gist options
  • Save tahir-hassan/17785c22364c64fa26aca51ed092e4c8 to your computer and use it in GitHub Desktop.
Save tahir-hassan/17785c22364c64fa26aca51ed092e4c8 to your computer and use it in GitHub Desktop.
A script that enables you to use Alt+F4 to exit the PowerShell instance.
Set-PSReadLineKeyHandler -Key 'Alt+F4' `
-BriefDescription ExitPowerShell `
-LongDescription "Exits PowerShell" `
-ScriptBlock {
param($key, $arg)
$line = $null;
$cursor = $null;
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $line, [ref] $cursor);
[Microsoft.PowerShell.PSConsoleReadLine]::Delete(0, $line.Length);
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("exit");
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine($null, $null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment