Make sure you have WSL with the Windows 10 Fall Creators Update installed. Ranger uses rifle
as a file handler
and you need its config file, rifle.conf
. If you dont have it (should be in ~/.config/ranger/rifle.conf
), run
the command ranger --copy-config=rifle
, then edit the resulting file.
To run Windows applications from Ranger, we will use cmd.exe /C start "" <file>
, which works after the Fall
Creators Update. The problem is that Ranger will feed in file paths using Unix pathing, but start
expects Windows
pathing. We will solve this by using sed
to translate the path.
Add below code to your rifle.conf
and you will be able to run Windows applications for the chosen file extensions.
ext docx?|xlsx?|pptx?|pdf = echo "$@" | sed -e 's;/mnt/\(.\);\1:;' -e 's/.*/"&"/' -e 's:/:\\:g' | xargs cmd.exe /C start ""
start
should be able to run applications associated with file extensions implicitly, but if for some reason it
doesnt work, you can also explicitly tell start
which executable to run. Just remove the ""
and add one of
excel
, winword
, powerpnt
, AcroRd32.exe
, etc. Note that in this case you will need one line in rifle.conf
for each application. As an example:
ext docx? = echo "$@" | sed -e 's;/mnt/\(.\);\1:;' -e 's/.*/"&"/' -e 's:/:\\:g' | xargs cmd.exe /C start winword
ext xlsx? = echo "$@" | sed -e 's;/mnt/\(.\);\1:;' -e 's/.*/"&"/' -e 's:/:\\:g' | xargs cmd.exe /C start excel
Update:
There is a command wslpath
that does path translation between Windows/Unix and Unix/Windows. This was added in
the 1704 release of WSL. There are no man pages for
wslpath
, but the release notes explain the command and its options.
Our code can therefore be simplified:
ext docx?|xlsx?|pptx?|pdf = wslpath -w "$@" | sed -e 's/.*/"&"/' | xargs cmd.exe /C start ""
Additional Reading
The command works. Thank you! However I'm trying to run the associated Windows applications for all file extensions. I don't know the proper command to "match all file extension" so I have to resort to this ugly solution:
The list is from dyne/file-extension-list. Just put this to your
~/.config/ranger/rifle.conf
.