Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Raukie
Copy link

@Raukie Raukie commented Mar 28, 2024

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

@Raukie
Copy link
Author

Raukie commented Mar 28, 2024

@microsoft-github-policy-service agree

@DHowett
Copy link
Member

DHowett commented Apr 9, 2024

Hey there! Sorry about the delay - we've got a couple vacations on the team and are working through a backlog. Thanks for your patience!

@Raukie
Copy link
Author

Raukie commented Apr 9, 2024

Thats fine, vacation is important haha.
thank you for the notice.

@Raukie
Copy link
Author

Raukie commented Apr 9, 2024

I think visual studio has accidentally auto formatted some things. I already took it it out i thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A shortcut to select file/files in the explorer. And copy that path to the terminal.
2 participants