Created
December 17, 2025 21:31
-
-
Save byigitt/eb417a66d228bb467bdcb81f0c6b767d to your computer and use it in GitHub Desktop.
Start terminal where you left off
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
| $lastDirFile = "$env:USERPROFILE\.last_powershell_dir" | |
| # On startup, go to the last saved directory | |
| if (Test-Path $lastDirFile) { | |
| $lastDir = (Get-Content $lastDirFile -Raw).Trim() | |
| if ($lastDir -and (Test-Path $lastDir)) { | |
| Set-Location $lastDir | |
| } | |
| } | |
| # Hook into every directory change | |
| $ExecutionContext.SessionState.InvokeCommand.LocationChangedAction = { | |
| $pwd.Path | Out-File $lastDirFile -NoNewline -Encoding utf8 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment