The best WSL Terminal is a Native Linux Terminal
Intro
Windows Subsystem Linux default terminal Prompt could have more features. It lack tabs, integration with Linux CLI applications, colors and customization which real Linux terminal, like GnomeTerminal/Konsole/XTerm have. The best solution, is to run a native Linux terminal from within WSL, then expose it using a Windows X11 Server.
Microsoft has a preview of the future Windows Terminal at its store at https://www.microsoft.com/en-us/p/windows-terminal-preview/9n0dx20hk701 . You can also find it on Github, now owned by Microsoft: https://github.com/microsoft/terminal .
This new terminal will resolve many issues, but still, it’s a Windows terminal. There is a trick to run an Windows X11 Server and expose the server to the applications running inside WSL. This way, I’`ll be running gnome-terminal and having one of the greatest WSL experiences using a native Linux Gnome Terminal as a Windows application.
Installing vcxsrv a Windows X11 Server
The first step, is to have a X11 server running on Windows. Let’s use https://sourceforge.net/projects/vcxsrv simply download and install it as any normal Windows application.
Installing gnome-terminal
Install gnome-terminal inside WSL Bash.
For Debian based distros, run
sudo apt install gnome-terminal dbus
If you are using an Fedora based distro, yo can install it with
sudo dnf install gnome-terminal dbus
Automatically start vcxsrv and gnome-terminal using VBScript
To automate starting the X11 server and launching gnome-terminal, we can use VBScript, that way we can also hide the Windows Prompt terminal that would appear as a normal bat script.
Create a launch-gnome-terminal.vbs script and insert the following content.
C:\wslterm\launch-gnome-terminal.vbs
Function CheckCommandIsRunning(ProcessName)
sComputerName = "."
Set objWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
sQuery = "SELECT * FROM Win32_Process WHERE CommandLine LIKE '%" + ProcessName + "%'"
Set objItems = objWMIService.ExecQuery(sQuery)
If objItems.Count > 0 Then
CheckCommandIsRunning = True
Else
CheckCommandIsRunning = False
End If
Set objWMIService = Nothing
Set objItems = Nothing
End Function
Function SilentlyStartCommand(Command)
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run Command, 0
Set WshShell = Nothing
End Function
If Not CheckCommandIsRunning("vcxsrv.exe") Then
SilentlyStartCommand """C:\Program Files\VcXsrv\vcxsrv.exe"" :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl"
WScript.Sleep 1000
End If
SilentlyStartCommand "C:\Windows\System32\Bash.exe -ic 'sudo service dbus start'"
SilentlyStartCommand "C:\Windows\System32\Bash.exe -ic 'DISPLAY=localhost:0 dbus-launch gnome-terminal'"
This script will check if VCXSRV is running, if not, it starts it. After checking that VCXSRV is running, it will use WSL Bash to run Gnome-Terminal. By using VBScript to launch those commands, we can also avoid having the Windows Prompt appearing while it starts the above commands. It also starts the dbus service, which is needed by gnome-terminal.
Creating a shortcut, to have a icon
The last step is to configure a icon for that VBscript. I found a Terminal icon at https://www.iconfinder.com/search/?q=Terminal