1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PowerShellのキーバインドをbash風にしたい

Last updated at Posted at 2023-01-06

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に書いた内容を適宜修正。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?