Skip to content

Commit

Permalink
This works for #15173, but no me gusta
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed May 1, 2023
1 parent 0726206 commit 3d1611f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
45 changes: 33 additions & 12 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ namespace winrt::TerminalApp::implementation

if (dispatchToElevatedWindow)
{
newTerminalArgs.StartingDirectory(_evaluatePathForCwd(newTerminalArgs.StartingDirectory()));
_OpenElevatedWT(newTerminalArgs);
}
else
Expand Down Expand Up @@ -1174,6 +1175,23 @@ namespace winrt::TerminalApp::implementation
}
}

winrt::hstring TerminalPage::_evaluatePathForCwd(const winrt::hstring& path)
{
auto resultPath{ path };
const bool looksLikeLinux = resultPath.size() == 1 &&
(resultPath[0] == L'~' || resultPath[0] == L'/');
// if (newWorkingDirectory.size() == 0 || looksLikeLinux)
if (!looksLikeLinux)
{ // We only want to resolve the new WD against the CWD if it doesn't look like a Linux path (see GH#592)
// auto cwdString{ wil::GetCurrentDirectoryW<std::wstring>() };
auto cwdString{ _WindowProperties.VirtualWorkingDirectory().c_str() };
std::filesystem::path cwd{ cwdString };
cwd /= path.c_str();
resultPath = winrt::hstring{ cwd.wstring() };
}
return resultPath;
}

// Method Description:
// - Creates a new connection based on the profile settings
// Arguments:
Expand Down Expand Up @@ -1242,18 +1260,18 @@ namespace winrt::TerminalApp::implementation
// construction, because the connection might not spawn the child
// process until later, on another thread, after we've already
// restored the CWD to its original value.
auto newWorkingDirectory{ settings.StartingDirectory() };
const bool looksLikeLinux = newWorkingDirectory.size() == 1 &&
(newWorkingDirectory[0] == L'~' || newWorkingDirectory[0] == L'/');
// if (newWorkingDirectory.size() == 0 || looksLikeLinux)
if (!looksLikeLinux)
{ // We only want to resolve the new WD against the CWD if it doesn't look like a Linux path (see GH#592)
// auto cwdString{ wil::GetCurrentDirectoryW<std::wstring>() };
auto cwdString{ _WindowProperties.VirtualWorkingDirectory().c_str() };
std::filesystem::path cwd{ cwdString };
cwd /= settings.StartingDirectory().c_str();
newWorkingDirectory = winrt::hstring{ cwd.wstring() };
}
auto newWorkingDirectory{ _evaluatePathForCwd(settings.StartingDirectory()) };
// const bool looksLikeLinux = newWorkingDirectory.size() == 1 &&
// (newWorkingDirectory[0] == L'~' || newWorkingDirectory[0] == L'/');
// // if (newWorkingDirectory.size() == 0 || looksLikeLinux)
// if (!looksLikeLinux)
// { // We only want to resolve the new WD against the CWD if it doesn't look like a Linux path (see GH#592)
// // auto cwdString{ wil::GetCurrentDirectoryW<std::wstring>() };
// auto cwdString{ _WindowProperties.VirtualWorkingDirectory().c_str() };
// std::filesystem::path cwd{ cwdString };
// cwd /= settings.StartingDirectory().c_str();
// newWorkingDirectory = winrt::hstring{ cwd.wstring() };
// }

auto conhostConn = TerminalConnection::ConptyConnection();
auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(settings.Commandline(),
Expand Down Expand Up @@ -4273,6 +4291,9 @@ namespace winrt::TerminalApp::implementation
// whatever the default profile's GUID is.

newTerminalArgs.Profile(::Microsoft::Console::Utils::GuidToString(profile.Guid()));

newTerminalArgs.StartingDirectory(_evaluatePathForCwd(controlSettings.DefaultSettings().StartingDirectory()));

_OpenElevatedWT(newTerminalArgs);
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ namespace winrt::TerminalApp::implementation
void _OpenNewTabDropdown();
HRESULT _OpenNewTab(const Microsoft::Terminal::Settings::Model::NewTerminalArgs& newTerminalArgs, winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection existingConnection = nullptr);
void _CreateNewTabFromPane(std::shared_ptr<Pane> pane, uint32_t insertPosition = -1);

winrt::hstring _evaluatePathForCwd(const winrt::hstring& path);

winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _CreateConnectionFromSettings(Microsoft::Terminal::Settings::Model::Profile profile, Microsoft::Terminal::Settings::Model::TerminalSettings settings, const bool inheritCursor);
winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection _duplicateConnectionForRestart(std::shared_ptr<Pane> pane);
void _restartPaneConnection(const std::shared_ptr<Pane>& pane);
Expand Down

0 comments on commit 3d1611f

Please sign in to comment.