Restore previous directories when using "Open windows from a previous session" #17788

Closed
opened 2026-01-31 05:53:26 +00:00 by claunia · 3 comments
Owner

Originally created by @alexgeek on GitHub (Jun 23, 2022).

Description of the new feature/enhancement

I generally have about 5 powershell tabs open that are coloured and named for different projects I between.
When I restart my PC windows terminal opens back up with the same tab names / colours due to the "Open windows from a previous session" setting but I then have to CD into all the directories. It would be a great improvement to automatically CD into the last used directory per tab.

Proposed technical implementation details (optional)

I'm not sure myself as not familiar with the codebase but I imagine could be something like:

  • on close for each tab
  • cache pwd
  • on open for each tab
  • cd to cached pwd

Would likely need to be enabled per profile as some may not even have these commands.

Originally created by @alexgeek on GitHub (Jun 23, 2022). # Description of the new feature/enhancement I generally have about 5 powershell tabs open that are coloured and named for different projects I between. When I restart my PC windows terminal opens back up with the same tab names / colours due to the "Open windows from a previous session" setting but I then have to CD into all the directories. It would be a great improvement to automatically CD into the last used directory per tab. # Proposed technical implementation details (optional) I'm not sure myself as not familiar with the codebase but I imagine could be something like: - on close for each tab - cache `pwd` - on open for each tab - `cd` to cached `pwd` Would likely need to be enabled per profile as some may not even have these commands.
Author
Owner

@zadjii-msft commented on GitHub (Jun 23, 2022):

The Terminal should already do this, assuming that you've configured your shell to tell the Terminal what the CWD is.

@zadjii-msft commented on GitHub (Jun 23, 2022): The Terminal should already do this, assuming that you've [configured your shell to tell the Terminal what the CWD is](https://docs.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory).
Author
Owner

@alexgeek commented on GitHub (Jun 23, 2022):

The Terminal should already do this, assuming that you've configured your shell to tell the Terminal what the CWD is.

Thanks I'll look at that. I tried it and it works buts overriding posh-git / oh-my-posh so I'll need to do some fiddling.

@alexgeek commented on GitHub (Jun 23, 2022): > The Terminal should already do this, assuming that you've [configured your shell to tell the Terminal what the CWD is](https://docs.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory). Thanks I'll look at that. I tried it and it works buts overriding posh-git / oh-my-posh so I'll need to do some fiddling.
Author
Owner

@alexgeek commented on GitHub (Jun 23, 2022):

This only seems to work on the first powershell tab I have open, the rest just open in home directory.
Is that expected or likely something wrong with my profile?

Thanks!

@alexgeek commented on GitHub (Jun 23, 2022): This only seems to work on the first powershell tab I have open, the rest just open in home directory. Is that expected or likely something wrong with my profile? Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17788