2

For those unfamiliar with msys2, it is a port of *nix programs to Windows. There, I could do things like:

$ some-prog ~/.profile
$ some-prog /c/Windows/System32/drivers/etc/hosts

some-prog could be any binary, regardless of whether they were general Windows programs or programs compiled with compilers in msys2. The paths would be transparently translated, thus giving that very *nix-ish vibe even when working with programs not part of msys2.

Currently, I'm checking out WSL/"Bash on Windows" (Creators Update), and I seem to have a problem.

For a Linux program, everything works fine:

~ $ nano ~/.

As expected, nano opens up with contents of ~/.profile.

When trying to invoke a Windows program though, there's an error:

~ $ "/mnt/c/Program Files/Sublime Text 3/subl.exe" ~/.profile
Unable to translate current working directory. Using C:\Users\Admin

And it opens up C:\home\<wsl_username>\.profile in Sublime Text, whereas the actual file should be %localappdata%\lxss\home\<wsl_username>\.profile.

Windows paths aren't better either:

~ $ "/mnt/c/Program Files/Sublime Text 3/subl.exe" /mnt/c/Windows/System32/drivers/etc/hosts
Unable to translate current working directory. Using C:\Users\Admin

This opens up C:\mnt\c\Windows\System32\drivers\etc\hosts, which is again the wrong path.

Is there a way I can have a correct, msys2-like path integration on WSL?

1
  • 1
    @Seth Edited my question. Apr 18 '17 at 12:26
1

You need something along the lines of cygpath from Cygwin, unfortunately there isn't a port of this to WSL yet... Then you could just run:

cd /
notepad.exe $(cygpath /etc/hosts)

For now, the closest substitute for cygpath at the moment is small program posted on redit called win2lin.exe.

For another reference, you can see the shell script that Atom (the text editor) just included with their newest version, atom.sh.

Or if you wanted to use nodejs and don't mind hardcoding your username, you could write:

var p = require("path")
var path = "C:\\Users\\me\\Desktop"
var sepa = path.split(p.win32.sep)
var newS = [].concat([sepa[0].toLowerCase()], sepa.slice(1))
var newP = "/mnt/" + p.posix.join.apply(p.posix, newS).replace(":", "")
// newP == "/mnt/c/Users/me/Desktop

For now, the easiest workaround is to make sure the windows binary you want to use is in your path (you can even use a symlink to the .exe to keep your path clean) and then cd to /mnt/c/PathToFileYouWantToEdit, then run your program like: atom.exe myExampleFile.

cd /mnt/c/Some/Path
notepad.exe SomeFile

If your goal is to edit files that are inside WSL but not accessible outside (everything outside of WSL's /mnt) then the easiest way is to install a WebDAV server inside of WSL allowing r/w access to /, and map that WebDAV server to a windows drive letter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.