Skip to content

Instantly share code, notes, and snippets.

@byigitt
Created December 17, 2025 21:31
Show Gist options
  • Select an option

  • Save byigitt/eb417a66d228bb467bdcb81f0c6b767d to your computer and use it in GitHub Desktop.

Select an option

Save byigitt/eb417a66d228bb467bdcb81f0c6b767d to your computer and use it in GitHub Desktop.
Start terminal where you left off
$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