Created
September 3, 2023 21:09
-
-
Save erlend/0bf98d04c9b773fb88f75556bfdd2685 to your computer and use it in GitHub Desktop.
Script for running GUI applications in Docker or OrbStack with XQuartz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cmd=$* | |
authorize() { | |
for host | |
do xhost | egrep -q "^INET6?:$host$" || xhost + $host | |
done | |
} | |
exec_cmd_with() { | |
exec ${cmd%%" $1 "*} $@ ${cmd#*" $1 "} | |
} | |
case "$cmd" in | |
"docker run "* | "docker "*" run "*) | |
authorize localhost | |
DISPLAY=host.docker.internal:0 exec_cmd_with run \ | |
-v /tmp/.X11-unix:/tmp/.X11-unix \ | |
-e DISPLAY | |
;; | |
orb | "orb "* | "orbctl run "*) | |
authorize localhost | |
DISPLAY=host.orb.internal:0 exec $cmd | |
;; | |
*) | |
echo "Sorry, but I don't know how to run \"$cmd\" with XQuartz." | |
exit 128 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment