zsh_history stores non-ascii character with strange encoding

Viewed 32

When I open my .zsh_history file, I found that some non-ascii characters in my history have strange encoding or something like that.

Here is a minimal example:

First, the .zshrc is

# zshrc
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history

I typed some commands with chinese character, exec zsh to save the history, and read .zsh_history file.

echo 字串測試 一二三
exec zsh
tail -3 .zsh_history

The result is replaced with some random weird characters.

echo 孃串測試 一亃七
exec zsh

the image

Also, when I use vim or any text editor to open this file, it opens this file use latin1 encoding and displays the following:

echo 孷串測試 ä¸äº¬ä¸©
exec zsh

the image

I cannot find an option to fix this, and I'm guessing it's an encoding problem. How can I force zsh to save the history in utf-8 encoding or there is another way to fix this?

0 Answers
Related