Skip to content

Instantly share code, notes, and snippets.

@ariel-co
Created April 18, 2025 16:14
Show Gist options
  • Select an option

  • Save ariel-co/2e43c3152a8d3380a3a26ca5fb6886fd to your computer and use it in GitHub Desktop.

Select an option

Save ariel-co/2e43c3152a8d3380a3a26ca5fb6886fd to your computer and use it in GitHub Desktop.
Powershell / Bash: use a separate history file for VS Code
# $Profile has the profile location
# Detect VS Code environment and change the history path
if ( $env:TERM_PROGRAM -eq "vscode" ) {
Set-PSReadLineOption -HistorySavePath ((Get-PSReadLineOption).HistorySavePath + "_vscode")
}
# Or, to preserve the file extension:
if ( $env:TERM_PROGRAM -eq "vscode" ) {
$h = (Get-PSReadLineOption).HistorySavePath
$a = @{ Path=(Split-Path -Parent $h)
ChildPath=((Split-Path -LeafBase $h) + "_vscode" + (Split-Path -Extension $h)) }
Set-PSReadLineOption -HistorySavePath (Join-Path @a)
}
# https://github.com/PowerShell/PSReadLine/issues/2698#issuecomment-2746033314
# For Bash, change the environment variable HISTFILE. Append to ~/.bashrc:
if [ "${TERM_PROGRAM:-}" == vscode ]; then
HISTFILE=${HISTFILE}_vscode
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment