How to open Windows file editing app from WSL

Max Koretskyi

This answer states that the following will be possible:

For example, from the WSL command line you'll be able to type code /mnt/c/Users/username/src/windows-file.txt to open a Windows file in VS Code, or type code /home/username/src/linux-file.txt to open a Linux file in VS Code.

is it already possible with the newest WSL 2 and Windows 11 21H2?

At this point what I can do from inside WSL is to open the folder like this:

explorer.exe .

Which is already pretty awesome. But it would be even better to instead of running:

nano myfile.txt

open the file in Notepad++:

notepadpp myfile.txt
CherryDT

Sure, you can run any Windows executable this way.

notepad.exe myfile.txt will work, for example.

If your Notepad++ is in your PATH, then notepad++.exe would work too - mine isn't, though, so I have to use the full path:

/mnt/c/Program\ Files/Notepad++/notepad++.exe myfile.txt

You can of course create a shell script or an alias to shorten this command.

Just note that if you specify a file with a path then you will have an issue because the Linux path is passed verbatim to the Windows executable, but that can be fixed with wslpath.

Here is an example shell script that you could put into ~/bin/notepadpp for example:

#!/bin/bash

/mnt/c/Program\ Files/Notepad++/notepad++.exe "$(wslpath -w "$1")"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive