Remove hardcoded --cd ~ from WSL terminal fragment profiles to support Terminal's startingDirectory (#13350)

* Initial plan

* Fix WSL terminal fragment profiles to support Terminal's startingDirectory

Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>

* clang format

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com>
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
This commit is contained in:
Copilot 2025-08-11 14:08:39 -07:00 committed by GitHub
parent 267bbb7426
commit 17bd3716b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -2678,13 +2678,20 @@ try
std::wstring systemDirectory; std::wstring systemDirectory;
THROW_IF_FAILED(wil::GetSystemDirectory(systemDirectory)); THROW_IF_FAILED(wil::GetSystemDirectory(systemDirectory));
e["commandline"] = WideToMultiByte(std::format( e["commandline"] =
L"{}\\{} {} {} {} {}", systemDirectory, WSL_BINARY_NAME, WSL_DISTRIBUTION_ID_ARG, distributionIdString, WSL_CHANGE_DIRECTORY_ARG, WSL_CWD_HOME)); WideToMultiByte(std::format(L"{}\\{} {} {}", systemDirectory, WSL_BINARY_NAME, WSL_DISTRIBUTION_ID_ARG, distributionIdString));
e["name"] = WideToMultiByte(Configuration.Name); e["name"] = WideToMultiByte(Configuration.Name);
e["guid"] = WideToMultiByte(distributionProfileId); e["guid"] = WideToMultiByte(distributionProfileId);
e["icon"] = WideToMultiByte(IconPath.native()); e["icon"] = WideToMultiByte(IconPath.native());
// Set default starting directory to home directory if not already specified
// This allows Windows Terminal to override with startingDirectory setting
if (e.find("startingDirectory") == e.end())
{
e["startingDirectory"] = "~";
}
// See https://github.com/microsoft/terminal/pull/18195. Supported in terminal >= 1.23 // See https://github.com/microsoft/terminal/pull/18195. Supported in terminal >= 1.23
e["pathTranslationStyle"] = "wsl"; e["pathTranslationStyle"] = "wsl";

View File

@ -2539,9 +2539,12 @@ Error code: Wsl/InstallDistro/WSL_E_DISTRO_NOT_FOUND
wil::GetSystemDirectoryW(systemDir); wil::GetSystemDirectoryW(systemDir);
VERIFY_ARE_EQUAL( VERIFY_ARE_EQUAL(
std::format("{}\\{} {} {} {} {}", systemDir, WSL_BINARY_NAME, WSL_DISTRIBUTION_ID_ARG, distroIdString, WSL_CHANGE_DIRECTORY_ARG, WSL_CWD_HOME), std::format("{}\\{} {} {}", systemDir, WSL_BINARY_NAME, WSL_DISTRIBUTION_ID_ARG, distroIdString),
launchProfile["commandline"].get<std::string>()); launchProfile["commandline"].get<std::string>());
// Verify that startingDirectory is set to home directory
VERIFY_ARE_EQUAL(launchProfile["startingDirectory"].get<std::string>(), "~");
auto iconLocation = wsl::shared::string::MultiByteToWide(launchProfile["icon"].get<std::string>()); auto iconLocation = wsl::shared::string::MultiByteToWide(launchProfile["icon"].get<std::string>());
if (defaultIcon) if (defaultIcon)
{ {