zshi icon indicating copy to clipboard operation
zshi copied to clipboard

$HISTFILE is set to a file in the temporary directory on macOS zsh

Open strugee opened this issue 1 year ago • 3 comments

In summary:

% uname -a
Darwin AJs-MacBook-Pro.local 20.6.0 Darwin Kernel Version 20.6.0: Tue Jun 21 20:50:28 PDT 2022; root:xnu-7195.141.32~1/RELEASE_X86_64 x86_64

% sw_vers
ProductName:	Mac OS X
ProductVersion:	10.16
BuildVersion:	20G730

% ./zshi 'echo test'
test

% echo $HISTFILE
/var/folders/xx/dj3x7jy138gbgzsvbstxglph0000gn/T//zsh.sAysNdaTuK/.zsh_history

The problem appears to be coming from this line in /etc/zshrc:

HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history

The embedded script in zshi sets ZDOTDIR to the correct, non-temporary path at the beginning and then resets it to the temporary path at the end in order to ensure that zsh continues loading startup files from the temporary directory. However, because the global zshrc is loaded in between the user's startup files, ZDOTDIR is set to the temporary directory, and the history file defined by this line therefore is also in the tempdir instead of where the user expected it (probably in ~).

strugee avatar Aug 05 '22 20:08 strugee

Thanks for reporting this.

If you send a PR with a fix, I'll merge it. I'm afraid I won't be fixing this myself.

romkatv avatar Aug 05 '22 21:08 romkatv

Totally understandable, thanks for the quick response. I was thinking about sending a PR but I'm not sure what the best approach is here... I could look into trying to do something similar for the site-wide startup files as is done for the user startup files? But I'm not sure that's actually workable. Would you still take patches even if it's just hacking up $HISTFILE specifically?

strugee avatar Aug 05 '22 21:08 strugee

Actually I think this can be fixed by fiddling with the GLOBAL_RCS option.

strugee avatar Aug 05 '22 21:08 strugee