- Windows 10 April 2018 Update (1803) and
Ubuntu 18.04 were used while preparing this post
If you want to open a genuine Linux terminal emulator from the right-click popup menu for the selected folder in Windows File Explorer, read on!
STEP 1 Get your favorite terminal emulator ready
WSL doesn't officially support running Linux GUI apps. Hence when you first install Ubuntu/WSL from the Store, it doesn't include any X Window related libraries or utility programs. So please check the following post for minimal X Window setup and make sure your Linux GUI terminal is properly running before linking it to the Windows File Explorer.
For this example, we'll be linking a terminal emulator named Tilix. But you shouldn't have any problem using any other terminal emulator.
sudo apt install tilix
STEP 2 Create a folder for WSL related scripts and assets
It can be any folder on any drive, but for the sake of simplicity, let's create it on C: drive and name it 'wsl': c:\wsl. If you've decided to use a different folder path, please make adjustments accordingly to the scripts and registry settings described in the next steps.
STEP 3 Create a VBScript file for executing a batch file without any flashing Console window
We can directly execute the batch file that will be created in Step 4 for actually setting up and launching your Linux terminal emulator. However, Windows always shows a Command Prompt window when executing a batch file; we couldn't find a way to completely hide it. By using this VBScript, we can silently run the batch file and only show your Linux terminal emulator.
If WScript.Arguments.Count <= 0 Then WScript.Quit End If bat = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\")) & WScript.Arguments(0) & ".bat" arg = "" If WScript.Arguments.Count > 1 Then arg = WScript.Arguments(1) End If CreateObject("WScript.Shell").Run """" & bat & """ """ & arg & """", 0, False
Please note that the above VBScript automatically attaches the ".bat" file extension to its first argument and executes it as if it's a batch file in the same folder.
STEP 4 Create a Windows batch file (*.bat) for launching your favorite Linux terminal emulator
@echo off REM ### Start X410 in Windowed Apps Mode. If X410 is already running in Desktop Mode, REM ### it'll be terminated first without any warning message box. start /B x410.exe /wm REM ### Setup a D-Bus instance that will be shared by all X-Window apps ubuntu1804.exe run "sh -ic 'if [ -z \"$(pidof dbus-launch)\" ]; then export DISPLAY=127.0.0.1:0.0; dbus-launch --exit-with-x11; fi;'" REM ### Go to the selected folder path and open your terminal app ubuntu1804.exe run "cd \"$(wslpath '%1')\"; export DISPLAY=127.0.0.1:0.0; exec tilix"
Many X-Window apps use the D-Bus for inter-process communication (IPC). If you don't setup a D-Bus instance that can be shared by all subsequently launched X-Window apps, a temporary D-Bus is created and automatically terminated when you close your terminal even if you use "nohup" or "disown" command. This can cause other X-Window apps that were launched from your terminal to exit since the D-Bus they were using is terminated.
For your information, if you want to launch an X-Window app and have it keep running even if you close your terminal, try using "nohup" or "disown" command. For example, the following launches 'gedit' and keep it opened:
gedit & disown
nohup gedit &
'nohup' command creates a 'nohup.out' file. If you don't want that file, you can do the following:
nohup gedit >/dev/null 2>&1 &
STEP 5 Create a registry file for setting up the right-click menu
Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\Directory] [HKEY_CURRENT_USER\Software\Classes\Directory\Background] [HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell] [HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\X410LinuxShell] @="Open X410 Linux shell here" [HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\X410LinuxShell\command] @="wscript.exe \"C:\\wsl\\bat-launcher.vbs\" \"open-x410-linux-shell-here\" \"%V\"" [HKEY_CURRENT_USER\Software\Classes\Directory\shell] [HKEY_CURRENT_USER\Software\Classes\Directory\shell\X410LinuxShell] @="Open X410 Linux shell here" [HKEY_CURRENT_USER\Software\Classes\Directory\shell\X410LinuxShell\command] @="wscript.exe \"C:\\wsl\\bat-launcher.vbs\" \"open-x410-linux-shell-here\" \"%V\""
If you're not using "c:\wsl" for the scripts created in Step 3 and 4, please make sure to adjust the paths for 'open-x410-linux-shell-here.vbs' and 'open-x410-linux-shell-here.bat' according to your setup.
Once you have the 'set-open-x410-linux-shell-here-menu.reg' file, you can import it to Windows registry by double-clicking it or using the 'Import' menu from the Windows 'regedit' program.
Applying a Theme to Your Terminal Emulator
If your Linux terminal emulator is using GTK+, you can apply a theme by setting the GTK_THEME environment variable before launching it from the batch file. For example, if you want to apply the 'Arc' theme:
STEP 1 Install the theme
sudo apt install arc-theme
You can check the currently available themes in '/usr/share/themes' folder.
STEP 2 Set GTK_THEME
ubuntu1804.exe run "cd \"$(wslpath '%1')\"; export DISPLAY=127.0.0.1:0.0; export GTK_THEME=Arc; exec tilix"
If a theme has a "dark" variant, it can be selected by the ":dark" suffix.
ubuntu1804.exe run "cd \"$(wslpath '%1')\"; export DISPLAY=127.0.0.1:0.0; export GTK_THEME=Arc:dark; exec tilix"
Installing Adapta Theme
If you're using Ubuntu 18.04 (Bionic) / WSL and interested in applying the Adapta theme to your Linux terminal, you need to install it from its PPA repository as it's not available on the official Ubuntu repositories:
sudo add-apt-repository -y ppa:tista/adapta sudo apt update sudo apt install adapta-gtk-theme
You should also install Roboto and Noto fonts:
sudo apt install fonts-roboto sudo apt install fonts-noto
After installing the theme, change the GTK_THEME environment variable to 'Adapta' (Light) or 'Adapta-Nokto' (Dark).
ubuntu1804.exe run "cd \"$(wslpath '%1')\"; export DISPLAY=127.0.0.1:0.0; export GTK_THEME=Adapta-Nokto; exec tilix"