[PR #16966] A shortcut to select file/files in the explorer. And copy that path to the terminal. #31078

Open
opened 2026-01-31 09:44:56 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/16966

State: closed
Merged: No


Summary of the Pull Request

A PR to add the functionality specified in #16965
It adds an shortcut, currently ctrl+o that open a file explorer dialog to select files.
When an file or files are selected the appropiate paths are pasted into the terminal.

It also takes in account if quotes are necessary. This is largely based on the same implementation that takes care of pasting paths for dragging and dropping into the terminal.

References and Relevant Issues

#16965

Detailed Description of the Pull Request / Additional comments

An pull request with code to implement #16965.
Known things that still have to be implemented is support for WSL. The code for WSL path support is there, however i was unable to find an function/variable to check if its in WSL context.

This is the code for wsl support. Where it says false there should be an bool called IsWsl.
The rest of the code is too take care of Path Mangling for WSL.

TerminalPage.cpp, Line 3005

   // Fix path for WSL, still has to be implemented
   if (false /*IsWsl*/)
   {
       std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/');

       if (fullPath.size() >= 2 && fullPath.at(1) == L':')
       {
           // C:/foo/bar -> Cc/foo/bar
           fullPath.at(1) = til::tolower_ascii(fullPath.at(0));
           // Cc/foo/bar -> /mnt/c/foo/bar
           fullPath.replace(0, 1, L"/mnt/");
       }
       else
       {
           static constexpr std::wstring_view wslPathPrefixes[] = { L"//wsl.localhost/", L"//wsl$/" };
           for (auto prefix : wslPathPrefixes)
           {
               if (til::starts_with(fullPath, prefix))
               {
                   if (const auto idx = fullPath.find(L'/', prefix.size()); idx != std::wstring::npos)
                   {
                       // //wsl.localhost/Ubuntu-18.04/foo/bar -> /foo/bar
                       fullPath.erase(0, idx);
                   }
                   else
                   {
                       // //wsl.localhost/Ubuntu-18.04 -> /
                       fullPath = L"/";
                   }
                   break;
               }
           }
       }
   }

Validation Steps Performed

PR Checklist

**Original Pull Request:** https://github.com/microsoft/terminal/pull/16966 **State:** closed **Merged:** No --- ## Summary of the Pull Request A PR to add the functionality specified in #16965 It adds an shortcut, currently ctrl+o that open a file explorer dialog to select files. When an file or files are selected the appropiate paths are pasted into the terminal. It also takes in account if quotes are necessary. This is largely based on the same implementation that takes care of pasting paths for dragging and dropping into the terminal. ## References and Relevant Issues #16965 ## Detailed Description of the Pull Request / Additional comments An pull request with code to implement #16965. Known things that still have to be implemented is support for WSL. The code for WSL path support is there, however i was unable to find an function/variable to check if its in WSL context. This is the code for wsl support. Where it says false there should be an bool called IsWsl. The rest of the code is too take care of Path Mangling for WSL. TerminalPage.cpp, Line 3005 ```cpp // Fix path for WSL, still has to be implemented if (false /*IsWsl*/) { std::replace(fullPath.begin(), fullPath.end(), L'\\', L'/'); if (fullPath.size() >= 2 && fullPath.at(1) == L':') { // C:/foo/bar -> Cc/foo/bar fullPath.at(1) = til::tolower_ascii(fullPath.at(0)); // Cc/foo/bar -> /mnt/c/foo/bar fullPath.replace(0, 1, L"/mnt/"); } else { static constexpr std::wstring_view wslPathPrefixes[] = { L"//wsl.localhost/", L"//wsl$/" }; for (auto prefix : wslPathPrefixes) { if (til::starts_with(fullPath, prefix)) { if (const auto idx = fullPath.find(L'/', prefix.size()); idx != std::wstring::npos) { // //wsl.localhost/Ubuntu-18.04/foo/bar -> /foo/bar fullPath.erase(0, idx); } else { // //wsl.localhost/Ubuntu-18.04 -> / fullPath = L"/"; } break; } } } } ``` ## Validation Steps Performed ## PR Checklist - [x] Closes #16965 - [x] Tests added/passed - [ ] Documentation updated - If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx - [ ] Schema updated (if necessary)
claunia added the pull-request label 2026-01-31 09:44:56 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31078