Skip to content

Instantly share code, notes, and snippets.

@erlend
Created September 3, 2023 21:09
Show Gist options
  • Save erlend/0bf98d04c9b773fb88f75556bfdd2685 to your computer and use it in GitHub Desktop.
Save erlend/0bf98d04c9b773fb88f75556bfdd2685 to your computer and use it in GitHub Desktop.
Script for running GUI applications in Docker or OrbStack with XQuartz
#!/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