-
-
Save raneomik/202f5adb964723b16d14c3799d28e1e2 to your computer and use it in GitHub Desktop.
' 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 |
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
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. 👏 👏 👏 👏
Nice, thanks! I did sneak in some High DPI environment variables in
RunTerminator
:shell.run "C:\Windows\System32\wsl.exe bash -c ""cd " & cdPath & "; export GDK_SCALE=0.5; export GDK_DPI_SCALE=2.0; DISPLAY=:0 terminator""", 0, true
This after fixing the high dpi for the x server in its properties, per other recommendations.