-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Remove hardcoded --cd ~ from WSL terminal fragment profiles to support Terminal's startingDirectory
#13350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@benhillis 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
…ctory Co-authored-by: benhillis <[email protected]>
--cd ~, which destroys Terminal's support for startingDirectory--cd ~ from WSL terminal fragment profiles to support Terminal's startingDirectory
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@DHowett - is this what you had in mind? |
DHowett
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benhillis looks good to me!
| // This allows Windows Terminal to override with startingDirectory setting | ||
| if (e.find("startingDirectory") == e.end()) | ||
| { | ||
| e["startingDirectory"] = "~"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DHowett: Does terminal know how to translate '~' to the proper path ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's special handling which, if I'm reading it correctly, will default to the Windows home directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Terminal passes ~ through to WSL if it knows it's launching WSL (per the comment below the linked line)
TL;DR: Terminal does not translate ~ at all if WSL is involved. It passes it along as --cd "~"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line you linked is solidly after all of the WSL --cd promotion attempts fail :)
WSL was generating terminal fragment profiles with hardcoded
--cd ~arguments in the command line, which prevented Windows Terminal from being able to override the starting directory using itsstartingDirectorysetting.Problem
When WSL creates fragment profiles for Windows Terminal, it was generating command lines like:
This hardcoded
--cd ~argument overrides anystartingDirectorysetting that users configure in Windows Terminal, making it impossible to start WSL distributions in directories other than the home directory.Solution
The fix removes the hardcoded
--cd ~arguments from the command line and instead ensures the fragment profile includes"startingDirectory": "~"in the JSON. This allows Windows Terminal to:~) when no override is specifiedstartingDirectoryin their Terminal settingsChanges
WSL_CHANGE_DIRECTORY_ARGandWSL_CWD_HOMEfrom the terminal profile command line"startingDirectory": "~"if not already specified by custom distribution templatesstartingDirectorypropertyBehavior
Before:
{ "commandline": "C:\\Windows\\System32\\wsl.exe --distribution-id {guid} --cd ~" }After:
{ "commandline": "C:\\Windows\\System32\\wsl.exe --distribution-id {guid}", "startingDirectory": "~" }The fix preserves backward compatibility while enabling Terminal's
startingDirectoryfunctionality. Desktop shortcuts continue to work correctly as they still use--cd ~(which is appropriate for shortcuts).Fixes #13346.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.