Skip to content

Commit

Permalink
fzfで履歴検索する
Browse files Browse the repository at this point in the history
まだ日本語を含む履歴はうまく検索できない。
というのも履歴ファイル自体はUTF-8で保存されてるのだが、powershellの
パイプでいつの間にかエンコードが変わってたりする。

    $OutputEncoding = [Text.Encoding]::UTF8

にすることで、fzfの絞り込み画面で日本語を表示することは出来た。
しかし実際に日本語を含む履歴を選択すると、
文字化けした文字がプロンプトに挿入されてしまう。

多分PSReadline側の問題っぽい。

- <span>https://github.com/PowerShell/PSReadLine/issues/1009</span>
  • Loading branch information
kai2nenobu committed Mar 12, 2020
1 parent 855f781 commit 0426984
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ Set-Alias dm docker-machine
if ($env:WT_SESSION) {
$OutputEncoding = [Text.Encoding]::UTF8
'Use utf-8 in only Windows Terminal'

Set-PSReadLineKeyHandler `
-BriefDescription _SearchHistoryByFzf `
-Description 'Search history by fzf command' `
-Key 'Ctrl+r' `
-ScriptBlock {
param($key, $arg)
$history=(Get-Content -Encoding UTF8 (Get-PSReadlineOption).HistorySavePath | fzf --tac --prompt 'Choose history: ' -0 -1)
if ($history) {
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($history)
}
}
}

"Read a profile from `"$profile`""

0 comments on commit 0426984

Please sign in to comment.