From e0400150d04a96bd482957569ce02b362e6cee8c Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Tue, 24 Mar 2026 20:46:16 +0200 Subject: [PATCH] Use `vs-pwsh` icons if applicable. (#19990) ## Summary of the Pull Request This PR updates `VsDevShellGenerator` to use the `vs-pwsh` icon in generated profiles, if modern PowerShell has been detected. ## References and Relevant Issues The icons were added in #17706, but are not used anywhere. ## Detailed Description of the Pull Request / Additional comments * Updated `VsDevShellGenerator::GetProfileCommandLine` to accept a `bool& isPwsh` parameter, which is set to whether the generated profile command line is using modern PowerShell. This value gets passed to `VsDevShellGenerator::GetProfileIconPath`'s new parameter, which determines whether to return the icon for `powershell` or `pwsh`. --- .../VsDevShellGenerator.cpp | 26 ++++++++++++------- .../VsDevShellGenerator.h | 7 ++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp b/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp index ce14532107..8ca00bd452 100644 --- a/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp +++ b/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp @@ -8,6 +8,16 @@ using namespace winrt::Microsoft::Terminal::Settings::Model; +static bool _IsPwshAvailable() +{ + // Try to detect if `pwsh.exe` is available in the PATH, if so we want to use that + // Allow some extra space in case user put it somewhere odd + // We do need to allocate space for the full path even if we don't want to paste the whole thing in + wchar_t pwshPath[MAX_PATH] = { 0 }; + const auto pwshExeName = L"pwsh.exe"; + return SearchPathW(nullptr, pwshExeName, nullptr, MAX_PATH, pwshPath, nullptr); +} + void VsDevShellGenerator::GenerateProfiles(const VsSetupConfiguration::VsSetupInstance& instance, bool hidden, std::vector>& profiles) const { try @@ -21,9 +31,10 @@ void VsDevShellGenerator::GenerateProfiles(const VsSetupConfiguration::VsSetupIn const winrt::guid profileGuid{ ::Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, std::as_bytes(std::span{ seed })) }; auto profile = winrt::make_self(profileGuid); profile->Name(winrt::hstring{ GetProfileName(instance) }); - profile->Commandline(winrt::hstring{ GetProfileCommandLine(instance) }); + auto isPwsh = _IsPwshAvailable(); + profile->Commandline(winrt::hstring{ GetProfileCommandLine(instance, isPwsh) }); profile->StartingDirectory(winrt::hstring{ instance.GetInstallationPath() }); - profile->Icon(winrt::hstring{ GetProfileIconPath() }); + profile->Icon(winrt::hstring{ GetProfileIconPath(isPwsh) }); profile->Hidden(hidden); profiles.emplace_back(std::move(profile)); } @@ -37,20 +48,15 @@ std::wstring VsDevShellGenerator::GetProfileName(const VsSetupConfiguration::VsS return name; } -std::wstring VsDevShellGenerator::GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance) const +std::wstring VsDevShellGenerator::GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance, bool isPwsh) const { // Build this in stages, so reserve space now std::wstring commandLine; commandLine.reserve(256); - // Try to detect if `pwsh.exe` is available in the PATH, if so we want to use that - // Allow some extra space in case user put it somewhere odd - // We do need to allocate space for the full path even if we don't want to paste the whole thing in - wchar_t pwshPath[MAX_PATH] = { 0 }; - const auto pwshExeName = L"pwsh.exe"; - if (SearchPathW(nullptr, pwshExeName, nullptr, MAX_PATH, pwshPath, nullptr)) + if (isPwsh) { - commandLine.append(pwshExeName); + commandLine.append(L"pwsh.exe"); } else { diff --git a/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.h b/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.h index d8b54752c8..6192f2683b 100644 --- a/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.h +++ b/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.h @@ -37,13 +37,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model return L"VsDevShell" + instance.GetInstanceId(); } - std::wstring GetProfileIconPath() const + std::wstring GetProfileIconPath(bool isPwsh) const { - return L"ms-appx:///ProfileIcons/vs-powershell.png"; + return isPwsh ? L"ms-appx:///ProfileIcons/vs-pwsh.png" : + L"ms-appx:///ProfileIcons/vs-powershell.png"; } std::wstring GetProfileName(const VsSetupConfiguration::VsSetupInstance& instance) const; - std::wstring GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance) const; + std::wstring GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance, bool isPwsh) const; std::wstring GetDevShellModulePath(const VsSetupConfiguration::VsSetupInstance& instance) const; }; };