Preserve custom HISTFILE in zsh shell integration#314615
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
Preserve custom HISTFILE in zsh shell integration#314615yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
When shell integration is injected for zsh, the rc script unconditionally reset HISTFILE to $USER_ZDOTDIR/.zsh_history before sourcing the user's .zshrc. This clobbered any HISTFILE the user had set via .zshenv or via the terminal.integrated.env.* setting. Capture any incoming HISTFILE in envMixin as VSCODE_ZSH_HISTFILE_ORIG, then restore it in shellIntegration-rc.zsh when present, falling back to the previous default otherwise. Fixes microsoft#169264
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @anthonykim1Matched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to ensure VS Code’s zsh shell integration does not clobber a user’s custom HISTFILE when shell integration is injected, restoring the original history file location instead of forcing $USER_ZDOTDIR/.zsh_history (fixes #169264).
Changes:
- Capture an incoming
HISTFILEvalue during zsh shell integration injection and pass it through asVSCODE_ZSH_HISTFILE_ORIG. - Update the injected zsh rc script to restore
HISTFILEfromVSCODE_ZSH_HISTFILE_ORIG(and unset the helper variable) when present. - Preserve the prior default behavior when no custom
HISTFILEwas detected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/vs/workbench/contrib/terminal/common/scripts/shellIntegration-rc.zsh | Restores HISTFILE from a helper env var during injected startup instead of always forcing the default path. |
| src/vs/platform/terminal/node/terminalEnvironment.ts | Records an existing HISTFILE into envMixin for zsh injection so the rc script can restore it. |
| if [[ -n "$VSCODE_ZSH_HISTFILE_ORIG" ]]; then | ||
| HISTFILE="$VSCODE_ZSH_HISTFILE_ORIG" | ||
| builtin unset VSCODE_ZSH_HISTFILE_ORIG | ||
| else |
| envMixin['USER_ZDOTDIR'] = userZdotdir; | ||
| // Record any custom HISTFILE so the shell integration script can restore it | ||
| // instead of overwriting it with the default location (see #169264). | ||
| if (env?.HISTFILE) { |
Comment on lines
+258
to
+262
| // Record any custom HISTFILE so the shell integration script can restore it | ||
| // instead of overwriting it with the default location (see #169264). | ||
| if (env?.HISTFILE) { | ||
| envMixin['VSCODE_ZSH_HISTFILE_ORIG'] = env.HISTFILE; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #169264
Summary
After #168396, the zsh shell integration rc script unconditionally resets
HISTFILEto$USER_ZDOTDIR/.zsh_historybefore sourcing the user's.zshrc. This clobbers anyHISTFILEvalue the user has set via~/.zshenvor via theterminal.integrated.env.*setting, even though.zshrchas not yet had a chance to override it back. As a resultenv | grep HISTalways shows the default location.This applies the plan @Tyriar outlined in the issue:
getShellIntegrationInjection(terminalEnvironment.ts) for thezshcase, if the incomingenvalready contains aHISTFILE, record it onenvMixinasVSCODE_ZSH_HISTFILE_ORIG.shellIntegration-rc.zsh, ifVSCODE_ZSH_HISTFILE_ORIGis set, restoreHISTFILEfrom it (and unset the helper var) instead of forcing the default. The previous behavior is preserved when no customHISTFILEwas set.The chosen env var name
VSCODE_ZSH_HISTFILE_ORIGis namespaced to avoid colliding with anything users may have in their environment.Test plan
terminal.integrated.env.linux/.osx, set"HISTFILE": "${HOME}/something_else", open a new zsh terminal, and confirmenv | grep HISTshows the custom path.~/.zshenv,export HISTFILE="$HOME/something_else", open a new zsh terminal, and confirmenv | grep HISTshows the custom path.HISTFILEset, open a new zsh terminal and confirmHISTFILEstill resolves to$USER_ZDOTDIR/.zsh_history(the prior default), so existing users are unaffected.VSCODE_ZSH_HISTFILE_ORIGis unset after the rc script runs.