#!/usr/bin/env bash # Run a command in Ghostty on a virtual X display and follow a scene script. # # xshot.sh "" # # Scene lines: key | type | sleep | shot # (shot saves the Ghostty window as /.png). set -euo pipefail scene=$1 out=$2 extra=$3 shift 3 export GDK_BACKEND=x11 LIBGL_ALWAYS_SOFTWARE=1 GSK_RENDERER=gl unset WAYLAND_DISPLAY DBUS_SESSION_BUS_ADDRESS # shellcheck disable=SC2016 # expanded by the inner shell xvfb-run -a -s "-screen 0 1800x1200x24" bash -c ' scene=$1 out=$2 extra=$3 shift 3 # shellcheck disable=SC2086 # extra holds several arguments ghostty --gtk-single-instance=false --class=arrshot --window-width=132 --window-height=38 \ --window-decoration=false --confirm-close-surface=false --font-size=12 \ --window-padding-x=8 --window-padding-y=6 $extra -e "$@" >/dev/null 2>&1 & ghostty=$! sleep 7 # Ghostty with software rendering takes a while to show its window wid=$(xdotool search --onlyvisible --pid "$ghostty" | tail -n1) while read -r cmd args; do case $cmd in key) for k in $args; do xdotool key "$k"; sleep 0.25; done ;; type) xdotool type --delay 80 "$args"; sleep 0.5 ;; sleep) sleep "$args" ;; shot) import -window "$wid" "$out/$args.png" ;; ""|"#"*) ;; *) echo "unknown scene command: $cmd" >&2; exit 1 ;; esac done < "$scene" kill "$ghostty" 2>/dev/null || true ' _ "$scene" "$out" "$extra" "$@"