2020/06/27

PowerShell で Ctrl+D で exit する

PowerShellの話なのかWindows Terminalの話かあんまりよくわかってないけど、たぶん PowerShellの話だと思いつつ、シェルを抜けるとき、自分は exit って打たない人なので、bashなんかと同じように Ctrl+D ショートカットで抜けたい。デフォルトのPowerShellだと抜けられない。そういうキーバインドはない。

Microsoft.PowerShell_profile.ps1 いわゆる profile.ps1 に以下のように書いておけば良い。

Import-Module PSReadLine
Set-PSReadlineKeyHandler -Key ctrl+d -Function DeleteCharOrExit

以下のstack overflowのページには AutoHotkey を利用したやりかた(参考 マウスホイールで仮想デスクトップを切り替えるのAutoHotkeyをつかった例 )なんかも載っている。

https://stackoverflow.com/questions/8360215/use-ctrl-d-to-exit-and-ctrl-l-to-cls-in-powershell-console

サイト内検索