Skip to content

fix: keep zsh history in the user's HISTFILE - #494

Open
taf (tashifkhan) wants to merge 1 commit into
microsoft:mainfrom
tashifkhan:fix/zsh-histfile
Open

taf (tashifkhan) wants to merge 1 commit into
microsoft:mainfrom
tashifkhan:fix/zsh-histfile

Conversation

@tashifkhan

Copy link
Copy Markdown

Fixes #493

On macOS, /etc/zshrc sets HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history before the user's .zshrc runs. Because inshellisense starts zsh with ZDOTDIR set to a per-session temporary directory, HISTFILE ends up pointing at $TMPDIR/is-zsh-<pid>/.zsh_history. History is then read from and saved to that file, so each new session starts empty.

This change sets HISTFILE back to $USER_ZDOTDIR/.zsh_history when it still points at the temporary directory. It runs before the user's .zshrc is sourced, so a HISTFILE set there still takes precedence. A HISTFILE set anywhere else, or left unset, is not changed.

Testing on macOS 27.2 with zsh 5.9 and a .zshrc that does not set HISTFILE:

  • Before: echo $HISTFILE printed $TMPDIR/is-zsh-<pid>/.zsh_history, and Up in a new session recalled nothing.
  • After: echo $HISTFILE prints ~/.zsh_history, and Up in a new session recalls entries from earlier sessions.
  • A custom HISTFILE set before the check is left unchanged.

On macOS, /etc/zshrc sets HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history before the user's .zshrc runs. inshellisense points ZDOTDIR at a per-session temporary directory, so history was read from and saved to that directory, and new sessions started with an empty history. Point HISTFILE back at USER_ZDOTDIR when it still refers to the temporary directory.
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 this pull request may close these issues.

zsh history is saved to a temporary directory on macOS

1 participant