Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
strugee opened this issue Aug 5, 2022 · 3 comments · May be fixed by #4
Open

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

strugee opened this issue Aug 5, 2022 · 3 comments · May be fixed by #4

Comments

@strugee
Copy link

strugee commented Aug 5, 2022

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 strugee changed the title HISTFILE is set to a file in the temporary directory on macOS zsh $HISTFILE is set to a file in the temporary directory on macOS zsh Aug 5, 2022
@romkatv
Copy link
Owner

romkatv commented Aug 5, 2022

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.

@strugee
Copy link
Author

strugee commented Aug 5, 2022

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
Copy link
Author

strugee commented Aug 5, 2022

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

strugee added a commit to strugee/zshi that referenced this issue Aug 5, 2022
We do this by disabling zsh's builtin behavior to read these startup
files and instead doing them ourselves. This allow us to exert control
over what ZDOTDIR is set to (we cannot just set ZDOTDIR to the right
thing before global startup scripts are executed because this would
cause zsh to not execute the custom startup scripts we wrote out to
the temporary directory).

In order to maintain compatibility with existing zsh behavior, we
stash the state of the GLOBAL_RCS option at the end of our custom
startup scripts but before disabling the option. We then restore its
state at the beginning of the next startup script (so immediately
after zsh *would* have executed the relevant global startup script).

Fixes romkatv#3
@strugee strugee linked a pull request Aug 5, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants