#!/usr/bin/env bash # slab-web — open a frameless WEB preview in slab. # # Two backends: # (default) AC Electron app — chromeless, CDP-attached (:9222), auto-tiles # into the terminal grid via the slab menubar's AXTiler. # --chrome your REAL Google Chrome, --app (frameless) mode, using your main # profile — so it's logged into everything you are (GitHub, etc.). # Best for authed pages (e.g. private PRs). Uses the running Chrome # instance (your session); CDP only if Chrome was started with a # --remote-debugging-port, and Chrome --app windows aren't # auto-tiled (can't be told apart from your normal Chrome windows). # # Usage: # slab-web # slab-web --chrome https://github.com/fuserstudio/fuser/pull/608 # slab-web ~/aesthetic-computer/studies/spatial-flow.html set -euo pipefail APP="Aesthetic.Computer" CHROME=0 if [ "${1:-}" = "--chrome" ] || [ "${1:-}" = "-c" ]; then CHROME=1; shift; fi url="${1:-}" [ -n "$url" ] || { echo "usage: slab-web [--chrome] " >&2; exit 1; } case "$url" in http://*|https://*|file://*) : ;; # full URL — as-is /*) url="file://$url" ;; # absolute path ./*|../*|*/*) url="file://$(cd "$(dirname "$url")" && pwd)/$(basename "$url")" ;; # relative path *.html) url="file://$PWD/$url" ;; # bare file in cwd *) url="https://aesthetic.computer/$url" ;; # bare token → AC piece/$code esac if [ "$CHROME" = "1" ]; then # Real Chrome, --app (frameless) mode, main profile (authed). Invoke the # binary directly so a running Chrome forwards the new app window into your # existing session instead of spawning an isolated instance. chrome="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" [ -x "$chrome" ] || { echo "Google Chrome not found at $chrome" >&2; exit 1; } "$chrome" --app="$url" >/dev/null 2>&1 & disown exit 0 fi # Default: AC Electron preview (chromeless, CDP, tiled). Resolve the installed # app (prefer /Applications; fall back to a Spotlight lookup by bundle id). app_path="/Applications/$APP.app" [ -d "$app_path" ] || app_path="$(mdfind "kMDItemCFBundleIdentifier == 'computer.aesthetic.app'" 2>/dev/null | head -1)" # `open -na … --args --preview=` routes through the AC app's single-instance # lock so the running instance opens the preview window (cold-launches if not up). # Equals form: Chromium can inject switches into argv; a space-separated # `--preview ` risks pairing the flag with an injected switch. exec open -na "$app_path" --args "--preview=$url"