Context Menu shortcut to WSL program in Microsoft Terminal
This blogpost is mostly stolen from Nick Janetakis.
I use WSL for lots of daily tasks, including editing text files in vim
. Together with Microsoft Terminal (which is actually open source), it makes working on a Windows desktop almost bearable.
However, I still use the Explorer to browse files mostly, and wanted a quick solution to open textfiles in vim
from there. M$ Terminal (wt
) supports tabs, but I normally don't use these at all, because a tmux
session is started when WSL is first launched. But a new tab is perfect for a quick edit window!
After wrapping my head around the options of wt
, this is what I came up with. -w 0
is "Window 0", aka the only Terminal I have open.
wt -w 0 -p <WT_PROFILE_NAME> --title <WINDOW_TITLE> wsl.exe -d <WSL_DISTRO> vi "$(wslpath '%1')"
Filling in the values for my use case:
wt -w 0 -p Debian --title QuickVim wsl.exe -d Debian vi "$(wslpath '%1')"
To make the context menu entry look nice, save the icon somewhere. Now all that's left to do is create the context menu option in the registry.
Here's an export of what I had to create - adjust as needed, save as .reg
, and import.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\QuickVim]
@="Open with Vim"
"Icon"="D:\\vim.ico"
[HKEY_CLASSES_ROOT\*\shell\QuickVim\command]
@="wt -w 0 -p Debian --title QuickVim wsl.exe -d Debian vi \"$(wslpath '%1')\""