microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.46k stars 822 forks source link

file URI's incompatible between wsl and windows. #3907

Closed ertwro closed 5 years ago

ertwro commented 5 years ago

I'm trying to open local html files as an output from a remote linux emacs session but the output lacks a colon in the drive letter and due to the file uri scheme it doesn't open.

(emacs)
xdg-open file:///c/Users/ertwr/.docsets/Bash.docset/Contents/Resources/Documents/bash/Aliases.html
(Browser)
file:///c/Users/ertwr/.docsets/Bash.docset/Contents/Resources/Documents/bash/Aliases.html

I have /c/Users/ertwr/AppData/Local/Vivaldi/Applications/vivaldi.exe boht in xdg-open and $BROWSER.

I've tried wslpath but it gives gets rid of the initial slashes from file file:/c:/Users/ert/... cmd.exe /c start doesn't work. I've tried using sed or awk scripts on the linux side, but is super inconsistent sometimes adding or removing slashes and whitespaces. Not to mention the firefox version inside wsl doesn't support GPU. So I'm stuck.

Biswa96 commented 5 years ago

Try to add /mnt/c.

ertwro commented 5 years ago

@Biswa96 Try to add it where? The reason I have /c/Users/ertwr/... is because my C: unit is mounted in /c/ not in /mnt/c in my WSL due to me modifying /etc/wsl.conf specifically to do so, because it actually reduces the number of problems when dealing with wslpath. Not just that, if not having /mnt/c was my issue cmd.exe /c start /path/to/file.html would work but it doesn't. /mnt/c is the default and it was in my WSL too when this and many more problems arose for me. If I try to input it into the Firefox, Vivaldi or Chrome browser versions of windows the browser opens, an address appears file:///mnt/c/ and it opens nothing. I'm trying to use the default windows web-browser to open local files from a remote session in a Linux system. This means, locally it requires access to the windows URI file system, this means a letter and a colon file:///c:/. So I've changed it from the default because it doesn't work for this and other use cases where a different approach has been more successful. Another thing is that if an HTML file is opened from the current directory in a shell's current relative path it opens the file in the windows browser without problems but different relative and absolute paths don't work. That's the reason I'm asking for URI compatibility as the name of my issue.

fpopineau commented 5 years ago

Hi, Not sure it will solve you problem, but I open most files from WSL/emacs using this quick hack:

(defun w32-shell-execute (operation document &optional parameters show-flag)
  (if (and operation (not (string= "open" operation)))
      (error "Don't know how to open %s" document)
    (call-process "/mnt/c/Windows/System32/cmd.exe" nil nil t "/c" "start" "\"\""
       (concat ""
           (replace-regexp-in-string "^/mnt/c/" "c:/"
               (replace-regexp-in-string "^\\(/mnt/c\\)?/home/Fabrice/" "c:/home/" document))
               "")))))

IE, I define w32-shell-executefunction which is existing in Emacs/Win32 but not in Emacs/Linux. My c:/Users/Fabrice/Documents directory is linked to c:/Home in Win32. I vastly prefer to use only one Chrome browser and I use the Win32 one. I can open any file (HTML, PowerPoint, Excel,...) from dired for example.

Regards;

ertwro commented 5 years ago

@fpopineau Many thanks. Unfortunately no. I had already tried a similar approach with cmd.exe /c start and replacing the regexp but it was inconsistent maybe because it's a remote session. Your hack is almost identical to mine. Thanks. Also, even if it worked it would not address the problem of both absolute and relative paths from the shell for bash.

therealkenc commented 5 years ago

Ran course. Ref #3832 for sport. There is probably a solution to "I've tried using sed or awk scripts on the linux side, but is super inconsistent sometimes adding or removing slashes and whitespaces" but you'll probably find a better audience on serverfault or similar.

ertwro commented 5 years ago

For anyone interested. I found a solution for the browser. Use a portable version of your browser and place it in a path included in your environmental variable. Either inside your shell .rc through export BINARY='/your/path/' or directly in windows. In my case, I use scoop as a package manager which accomplishes both. Next use the following script:

Don't forget to adapt the regular expresion to your mount point in wsl.conf In my case is root = /

#!/usr/sbin/env bash
IFS=$'\n'

if [[ "$@" =~ \/([a-zA-Z]+)\/ ]]; then 
    "${HOME}/scoop/shims/chrome.exe" "${@/$BASH_REMATCH/${BASH_REMATCH[1]}\:\/}"
fi

if your mount folders are in /mnt the regular expression should be: if [[ "$@" =~ \/mnt\/([a-zA-Z]+)\/ ]]; then Add it to your path and export it as your browser.