-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Drag & Drop from File Explorer produces incorrect file paths with WSL #331
Comments
There's not really a way for us as the console/terminal to be able to know what format the shell running attached to us wants the path in. I wouldn't even begin to know how to begin implementing this. I've filed MSFT:19977636 to track this request, but I don't think it's going to go anywhere any time soon, especially without any plan for how it'd be possible. |
Thanks Mike. Since I'm the one who rudely punted here, I should probably speak up. That wasn't the answer I expected, but I understand the answer. WSL (on its end of the pty) has no business knowing what you are doing when a file is dropped onto your window. On your end of the pty, you are saying (point blank): hey I have no idea how WSL wants that path string to look. I don't even know it is WSL. Impasse. The popular competing terminal emulator implements this by throwing out separation of concerns. The emulator knows the context of the thing that launched it (historically that meant Cygwin). You can do the same. So for The other way to do this is inversion of control. You provide a hook, which Academic, I know. Beats empty proposition. |
The problem is that the paste is seen by conhost, that will then emulate keypresses to be sent to the underlying console application. I would suppose that in the WSL it's either wsl.exe or bash.exe (??) and they would have to detect that the thing you are entering at this precise moment is a file path (rather than "random" keypresses), and then do a path conversion "à la Cygwin". The problem here of course is that detection. Unless, it is possible, from within conhost, to "detect" whether the console application that has the focus (is the main) in the given console, will expect *nix-type file paths instead of win32-type file paths. An alternative way (that is inspired from Wolfram Mathematica when you paste file paths in a string), would be to recognize that the file path has a certain form, namely "driver_letter:\path\to\file" . If such recognition can be performed, then one can then convert this type of string to a *nix-formatted file path. EDIT: You can check how git-bash / cygwin proceeds. If you paste a win32-formatted path enclosed in quotes, like for example in: |
Hi, can this please be implemented? It's pretty trivial as far as i can tell, the parent process for conhost is wsl.exe so all it needs to do is check the module name of it's parent process. This can be done a number of ways, the easiest of which is probably just enumerating the processes and checking pids. If one is found get the window name and check for 'wsl.exe': https://gist.github.com/mattn/253013/d47b90159cf8ffa4d92448614b748aa1d235ebe4 (additionally should probably verify the parent start time is before child start time). OR wslhost could simply be modified to pass a handle of itself down to conhost. Either way this is an insanely useful feature. |
Ah but what if you're running
EDIT: I realized I'm dumb - I'm pretty sure that extra conhost is the one they use as a conpty for Windows interop, which I maybe helped write 🥚->🤕 |
wslhost.exe is always the parent of conhost for wsl systems afaik. The wsl.exe is parent of cmd.exe when spawned from within a wsl2 environment. Grab process hacker2 and try for yourself. But since this is all microsoft code the correct solution would be to just have the parent pass a handle to itself down to the child to detect this. This is entirely solvable. |
I'd also love this feature - I think it could be implemented with a combination of two options for profiles:
This would solve the problem without requiring the terminal to know what's running (except for knowledge of which profile is open, which it already has). |
Drag and drop does not work for WSL because paths are pasted as windows paths having incorrect path separator and path root. This PR adds code to correct the path in TerminalControl before pasting to WSL terminals. One problem with this approach is that it assumes the default WSL automount root of "/mnt". It would be possible to add a setting like "WslDragAndDropMountRoot"... but I decided it if someone wants to change automount location it would be simple enough just to create the "/mnt" symlink in WSL. ## Validation Couldn't find an obvious place to add a test. Manually tested cut-n-paste from following paths: - "c:\" - "c:\subdir" - "c:\subdir\subdir" - "\\wsl.localhost\<distro>" - \\wsl.localhost\<distro>\subdir" Closes #331
🎉This issue was addressed in #11625, which has now been successfully released as Handy links: |
Has no effect on WSL Ubuntu 22.04.1 LTS. Ubuntu 22.04.1 LTS installed from the Microsoft Store is configured in this way, so it is not determined correctly.
|
FWIW, This is an excellent example of why I always thought that pushing the source down into the control layer to make the decision about drag/drop was the wrong thing to do. Hmm. |
This feature that automatically converts the dropped file path according to the shell/OS is very convenient. settings.json
↓
#1772 (comment) |
Dragging & dropping a file from Windows File Explorer into a Bash window produces the path formatted for Windows instead of Ubuntu.
Dragging the Desktop folder into a Bash window should produce the text /mnt/c/Users/acesnik/Desktop. Instead, it produces C:\Users\acesnik\Desktop.
Your Windows build number
Edition: Windows 10 Pro
Version: 1607
OS Build: 14393.576
See also microsoft/WSL#1501
The text was updated successfully, but these errors were encountered: