This project provides a PowerShell profile script that enables project-specific command history when using VS Code's integrated terminal. It ensures that PowerShell command history is stored separately for each project, avoiding conflicts between different repositories.
- Project-Specific History: Each project has its own history file.
- Global History Support: Uses global history when running standalone PowerShell.
- Automatic History Loading & Saving: Ensures past commands persist across sessions.
- Configurable Profile Settings: Allows users to enable/disable history and profile path display.
git clone https://github.com/your-username/VSCode-PowerShell-History.git
cd VSCode-PowerShell-History
powershell -ExecutionPolicy Bypass -File setup.ps1
The script will:
- Backup your existing PowerShell profile.
- Copy the new profile script to your PowerShell profile directory.
- Ask for user preferences (whether to display history and profile path on startup).
- Apply changes and set up history management.
When using VS Code, the script creates a unique history file for each project:
C:\Users\YourUser\.ps_history\D_Projects_MyProject.pshistory
The filename is derived from the full project path, replacing :
and \
with _
to prevent invalid characters.
If not running inside VS Code, PowerShell will use the global history file:
C:\Users\YourUser\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
After installation, you can modify these preferences inside your PowerShell profile ($PROFILE
):
$ShowHistoryPath = $True # Set to $False to disable history file path display
$ShowProfilePath = $True # Set to $False to disable profile path display
- In VS Code Terminal
-
Run some commands, close & reopen VS Code.
-
Press the Up Arrow (↑) → You should see only project-specific history.
- In Standalone PowerShell
-
Run some commands, close & reopen PowerShell.
-
Press the Up Arrow (↑) → You should see only global history.
If you want to remove this setup, run:
Remove-Item -Path $PROFILE -Force
Restore backup:
Copy-Item -Path "$PROFILE.bak" -Destination "$PROFILE" -Force
Then restart your terminal.
- "Access Denied" Errors? Run PowerShell with administrator privileges.
- History File Not Found? Ensure that
PSReadLine
is installed:Install-Module PSReadLine -Force
- Profile Not Loading? Check if
$PROFILE
is correctly pointing toMicrosoft.PowerShell_profile.ps1
:Write-Output $PROFILE
VSCode PowerShell History Manager by Sahil Goyal is licensed under CC BY-NC-SA 4.0
- 🆓 You can use, modify, and share this project non-commercially
- 🏷️ You must give proper credit to the original author
- 🔄 If you modify this project, you must use the same license
🔗 Read more about this license: CC BY-NC-SA 4.0