Skip to content

Instantly share code, notes, and snippets.

@nv-h
Last active November 15, 2021 05:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nv-h/081684cee2505cd336e26c2660fc7541 to your computer and use it in GitHub Desktop.
Save nv-h/081684cee2505cd336e26c2660fc7541 to your computer and use it in GitHub Desktop.
Windows PowerShell Ctrl+R history with fzf
# PowerShell Core7でもConsoleのデフォルトエンコーディングはsjisなので必要
[System.Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("utf-8")
[System.Console]::InputEncoding = [System.Text.Encoding]::GetEncoding("utf-8")
# git logなどのマルチバイト文字を表示させるため (絵文字含む)
$env:LESSCHARSET = "utf-8"
# 音を消す
Set-PSReadlineOption -BellStyle None
# 履歴検索
Set-PSReadLineKeyHandler -Chord Ctrl+r -ScriptBlock {
# いつからかawkの表示がされないようになったので、以下コマンドを実行
# Set-Alias awk C:\Users\saido\scoop\apps\msys2\current\usr\bin\awk.exe
$command = Get-Content (Get-PSReadlineOption).HistorySavePath | awk '!a[$0]++' | fzf --tac
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($command)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment