Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
VBS Script to Launch Terminator through WSL
args = "-c" & " -l " & """DISPLAY=:0 terminator"""
WScript.CreateObject("Shell.Application").ShellExecute "bash", args, "", "open", 0
@nistath

This comment has been minimized.

Copy link

@nistath nistath commented Oct 11, 2018

Hey, I forked your script and made it a tad better here!
Thanks for figuring out the VBS magic.
https://gist.github.com/nistath/a9236b737b15609bc0ea6e86fe3823df

@GregRos

This comment has been minimized.

Copy link

@GregRos GregRos commented Apr 27, 2019

Here is another improvement. Microsoft has recently introduced wsl.exe, which uses the default shell instead of always bash, and deprecated bash.exe. This version also defaults to ~ if no argument is provided.

https://gist.github.com/GregRos/6d4ad376cebe7ce1c9e52deaf90171d3

@avinoamsn

This comment has been minimized.

Copy link

@avinoamsn avinoamsn commented Aug 30, 2019

I created a version of my own, which quietly checks to see if vsxsrv is running (starts it if not), then opens a terminator window in WSL.
https://gist.github.com/avinoamsn/495db3729d6b24ec065a710250657c16

@raneomik

This comment has been minimized.

Copy link

@raneomik raneomik commented Oct 6, 2019

Hello, >here< is a combination of the previous solutions, adding also xServer quitting on terminator quit (if it is the only program for which xServer is needed...).
The argument check to pass it to "cd" is really nice, for example if you wish to >add terminator to the right click menu<, or launch it in IDEs embedding terminals

@g-spacewhale

This comment has been minimized.

Copy link

@g-spacewhale g-spacewhale commented Apr 4, 2020

Regarding scale issues on high dpi screens.
After changing the DPI settings to 'application' in the properties of my xserver and editing GDK_SCALE in the bashrc, terminator scales correctly when opening it via cmd.

For some reason I could not get GDK_SCALE=2 in my ~/.bashrc to work when launching terminator via the scripts in this thread.
Based on the original script I changed the args to args = "-c" & " -l " & """GDK_SCALE=2 GDK_DPI_SCALE=0.8 DISPLAY=:0 terminator""". This fixes the scaling for me - but I'd rather have it work directly the ~/.bashrc. Does anybody have a prettier solution to High DPI screens using this script?

@PauloDanielCarneiro

This comment has been minimized.

Copy link

@PauloDanielCarneiro PauloDanielCarneiro commented Jul 1, 2020

Hello, >here< is a combination of the previous solutions, adding also xServer quitting on terminator quit (if it is the only program for which xServer is needed...).
The argument check to pass it to "cd" is really nice, for example if you wish to >add terminator to the right click menu<, or launch it in IDEs embedding terminals

It would be nice mentioning that, for wsl2, you can use
shell.run "C:\Windows\System32\wsl.exe bash -c ""cd " & cdPath & "; DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 terminator""", 0, true
instead of
shell.run "C:\Windows\System32\wsl.exe bash -c ""cd " & cdPath & "; DISPLAY=:0 terminator""", 0, true

@kamermans

This comment has been minimized.

Copy link

@kamermans kamermans commented Nov 11, 2020

@g-spacewhale I fixed the High DPI scaling issue in VcXsrv directly by setting the "High DPI scaling override" to "Application":

image

@zoloholic

This comment has been minimized.

Copy link

@zoloholic zoloholic commented Dec 19, 2020

I created a version of my own, which quietly checks to see if vsxsrv is running (starts it if not), then opens a terminator window in WSL.
https://gist.github.com/avinoamsn/495db3729d6b24ec065a710250657c16

For WSL2 - Requires Shell nameserver IP address for DISPLAY

I have edited your script to work with WSL2. Please see below if you're using WSL2

' https://medium.com/@bhupathy/install-terminator-on-windows-with-wsl-2826591d2156
set shell = WScript.CreateObject("Shell.Application")

if not IsProcessRunning("vcxsrv.exe") then
shell.shellExecute "vcxsrv.exe", ":0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl -dpi auto", "C:\Program Files\VcXsrv", "", 0
end if
' terminator.vbs
myCd = "~"
If WScript.Arguments.Length > 0 Then
myCd = "'$(wslpath -u '" & WScript.Arguments(0) & "')'"
End If
args = "bash" & " -c ""cd " & myCd & "; DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0 terminator"""
WScript.CreateObject("Shell.Application").ShellExecute "C:\Windows\System32\wsl.exe", args, "", "open", 0

' https://stackoverflow.com/questions/19794726/vb-script-how-to-tell-if-a-program-is-already-running
Function IsProcessRunning( strProcess )
Dim Process, strObject
IsProcessRunning = False
strObject = "winmgmts://."
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = True
Exit Function
End If
Next
End Function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment