Skip to content

Instantly share code, notes, and snippets.

@kevinmilner
Last active February 19, 2020 18:49
Show Gist options
  • Save kevinmilner/b33475efc6afaaab533186ea4b84bc27 to your computer and use it in GitHub Desktop.
Save kevinmilner/b33475efc6afaaab533186ea4b84bc27 to your computer and use it in GitHub Desktop.
Windows batch script to reliably launch gnome-terminal (or another terminal) in WSL
tasklist /FI "IMAGENAME eq vcxsrv.exe" 2>NUL | find /I /N "vcxsrv.exe">NUL
if "%ERRORLEVEL%"=="0" echo X server is running
if not "%ERRORLEVEL%"=="0" start "" "C:\Program Files\VcXsrv\vcxsrv.exe" :0 -ac -terminate -lesspointer -multiwindow -clipboard -dpi auto
chcp utf8
ubuntu run "sh -ic 'if [ -z \"$(pidof dbus-launch)\" ]; then export DISPLAY=127.0.0.1:0.0; dbus-launch --exit-with-x11; fi;'"
ubuntu run "DISPLAY=:0 gnome-terminal --working-directory=/home/kevin; sleep 1"
@kevinmilner
Copy link
Author

This script will reliable start VcXsrv (if not running). then start DBus if not running, then finally launch a terminal. The second step avoids a problem where it would only otherwise work by first launching a regular ubuntu instance. Replace 'ubuntu' and the home directory as necessary.

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