What's?
タイトルどおり、PowerShellのキーバインドをbash風にしたいなということで。
bashの感覚だと、PowerShellが操作しづらかったので…。
環境
PS C:\Users\xxxxx> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 2364
$PRIFILE
に、以下のように設定。
$PROFILE
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function DeleteChar
Set-PSReadLineKeyHandler -Key "Ctrl+w" -Function BackwardKillWord
Set-PSReadLineKeyHandler -Key "Ctrl+k" -Function ForwardDeleteLine
Set-PSReadLineKeyHandler -Key "Ctrl+a" -Function BeginningOfLine
Set-PSReadLineKeyHandler -Key "Ctrl+e" -Function EndOfLine
Set-PSReadLineKeyHandler -Key "Ctrl+f" -Function ForwardChar
Set-PSReadLineKeyHandler -Key "Ctrl+b" -Function BackwardChar
Set-PSReadLineKeyHandler -Key "Ctrl+p" -Function PreviousHistory
Set-PSReadLineKeyHandler -Key "Ctrl+n" -Function NextHistory
Set-PSReadLineKeyHandler -Key "Ctrl+i" -Function MenuComplete
PowerShellプロファイルはPowerShell の開始時に実行されるスクリプトで、$PROFILE
は現在のセッションにおけるPowerShellプロファイルへのパスが入っています。
$PROFILE 自動変数には、現在のセッションで使用できる PowerShell プロファイルへのパスが格納されます。
$PROFILE
が指すファイルが存在しない場合は作成しましょう。
PS C:\Users\xxxxx> New-Item -ItemType File -Path $PROFILE -Force
実行ポリシーは、以下のようにしておきました。
PS C:\Users\xxxxx> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
現在のキーバインドを確認するには
Get-PSReadLineKeyHandler
コマンドで。
こちらを見ながら、必要に応じて$PROFILE
に書いた内容を適宜修正。