Powershellをいい感じに設定する

Powershellにおいて、.zshrcや.bashrcにあたるのがprofile.ps1。 echo $PROFILEにどこのパスに設定ファイルを置けばいいか書いてある。 自分の場合はC:\Users\Name\OneDrive\ドキュメント\PowerShell\Microsoft.PowerShell_profile.ps1だった。 profile.ps1に以下を書いた。

Set-PSReadLineOption -EditMode Emacs -BellStyle None
Set-PSReadLineKeyHandler -Chord Ctrl+d -Function DeleteChar
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
function prompt {
  "$($pwd.path)`n> "
}

Set-Alias v gvim

Emacsキーバインドが使える。Windowsコマンドラインで使えるなんて感動すら覚える。

Set-PSReadLineOption -EditMode Emacs -BellStyle None

デフォルトのEmacsキーバインドそのままだとC-dがDeleteCharOrExitになっていて、空文字をC-dするとプロセスをexitする。そこをなしに。

Set-PSReadLineKeyHandler -Chord Ctrl+d -Function DeleteChar

コマンド入力履歴を上下で辿るときにすでに入力している文字にマッチする履歴のみを辿る。zshっぽい。

Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

既に入力している文字から補完候補一覧を表示して、その中から選択するような形で補完できる。zshっぽい。

Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

プロンプト設定。色も付けられる。

function prompt {
  #"$($pwd.path)`n> "
  "`e[34m$($pwd.path)`e[0m`n> "
}

いまだにvscodeに乗り換えられないの良くないのかもしれない。

Set-Alias v gvim

これだけ設定するだけで十分に使えるようになった。