Remove hardcoded --cd ~ from WSL terminal fragment profiles to support Terminal's startingDirectory#13350
Remove hardcoded --cd ~ from WSL terminal fragment profiles to support Terminal's startingDirectory#13350
--cd ~ from WSL terminal fragment profiles to support Terminal's startingDirectory#13350Conversation
|
@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 <17727402+benhillis@users.noreply.github.com>
--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? |
| // This allows Windows Terminal to override with startingDirectory setting | ||
| if (e.find("startingDirectory") == e.end()) | ||
| { | ||
| e["startingDirectory"] = "~"; |
There was a problem hiding this comment.
@DHowett: Does terminal know how to translate '~' to the proper path ?
There was a problem hiding this comment.
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.
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.
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.