Skip to content

Instantly share code, notes, and snippets.

@raneomik
Last active January 27, 2024 03:58
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save raneomik/202f5adb964723b16d14c3799d28e1e2 to your computer and use it in GitHub Desktop.
Save raneomik/202f5adb964723b16d14c3799d28e1e2 to your computer and use it in GitHub Desktop.
vbscript to run Terminator and xServer under wsl
' https://medium.com/@bhupathy/install-terminator-on-windows-with-wsl-2826591d2156
set shell = CreateObject("Wscript.Shell")
xServerProcessName = "vcxsrv.exe"
RunXserverProcess( xServerProcessName )
RunTerminator()
KillXserverProcess( xServerProcessName )
function RunXserverProcess( strProcess )
'https://gist.github.com/avinoamsn/495db3729d6b24ec065a710250657c16
if getProcessObject(strProcess) is Nothing Then
shell.exec "C:\Program Files\VcXsrv\" & strProcess & " :0 -ac -terminate -lesspointer -multiwindow -clipboard -wgl -dpi auto"
end if
end function
function RunTerminator()
'https://gist.github.com/GregRos/6d4ad376cebe7ce1c9e52deaf90171d3
cdPath = "~"
if WScript.Arguments.Length > 0 Then
cdPath = "'$(wslpath -u '" & WScript.Arguments(0) & "')'"
end if
'https://stackoverflow.com/questions/38969503/shellexecute-and-wait
'Wscript.Shell.Run instead of Wscript.Shell.Application.ShellExecute - avoid async shell run and allow execution of code bellow
shell.run "C:\Windows\System32\wsl.exe bash -c ""cd " & cdPath & "; DISPLAY=:0 terminator""", 0, true
end function
function KillXserverProcess ( strProcess )
'Check if another bash process is running to avoid closing xServer
if Not getProcessObject("bash") is Nothing Then
exit function
end if
set Process = getProcessObject(strProcess)
if Not Process is Nothing Then
Process.terminate
end if
end function
function getProcessObject ( strProcess )
' https://stackoverflow.com/questions/19794726/vb-script-how-to-tell-if-a-program-is-already-running
Dim Process, strObject : strObject = "winmgmts://."
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
if UCase( Process.name ) = UCase( strProcess ) Then
set getProcessObject = Process
exit Function
end if
Next
set getProcessObject = Nothing
end function
@PauloDanielCarneiro
Copy link

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

@LuisCusihuaman
Copy link

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

Uff bro, thanks for your contribution! Without this, it didn't work for me. 👏 👏 👏 👏

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