-
-
Save ropnop/10800fb5066bd5144d9aaad55a8a4d18 to your computer and use it in GitHub Desktop.
args = "-c" & " -l " & """DISPLAY=:0 terminator""" | |
WScript.CreateObject("Shell.Application").ShellExecute "bash", args, "", "open", 0 |
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
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
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
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?
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
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
how do I make same kind of .vbs to run subl?
@chazakki Are you asking about starting subl from within WSL using a similar script? You'll probably only need to change the call to WScript.CreateObject(...)...
, but I couldn't say what the exact solution is. I bet that there are other examples out there that are closer to what you're looking for.
Additionally, I haven't used subl in years but VSCode runs natively in WSL using a proprietary VSCode server solution. subl may offer something similar, but I haven't looked into this myself.
Automatically retrieve the ip address related to your WSL2 adapter using adapter name in the function GetIpFromAdapter
, in VBS :
' https://gist.github.com/ropnop/10800fb5066bd5144d9aaad55a8a4d18
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
WScript.Sleep 2000
end if
StrIP=GetIpFromAdapter("Hyper-V Virtual Ethernet Adapter #2")
shell.ShellExecute "bash", "-c -l ""DISPLAY="&StrIP &":0 terminator""", "", "open", 0
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
Function GetIpFromAdapter( adapterName )
dim NIC1, Nic
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled And Nic.Description=adapterName then
GetIpFromAdapter = Nic.IPAddress(0)
End if
Next
End Function
i used this script since last year. (Many thanks!) After i upgraded my windows to 11 it stopped working and i cant seem to find the problem.
Do you have any experience with terminator wsl2 and windows 11?
Giant PITA!
i used this script since last year. (Many thanks!) After i upgraded my windows to 11 it stopped working and i cant seem to find the problem. Do you have any experience with terminator wsl2 and windows 11?
Windows 11 does not need this script. When you install a program in wsl, you can find windows start menu with its name and you'll see with icon if exist
I added home directory changes and more reliable IP calculation:
' https://gist.github.com/ropnop/10800fb5066bd5144d9aaad55a8a4d18
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
WScript.Sleep 2000
end if
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"""
shell.ShellExecute "C:\Windows\System32\wsl.exe", args, "", "open", 0
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
Thanks @fahri314
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