# Klammertext via Apple's `container` — macOS (Apple Silicon) shell wrapper # ----------------------------------------------------------------------------- # Lets you run Klammertext without typing the full `container run ...` command. # Install: save this file (e.g. ~/klammertext.zsh) and add to your ~/.zshrc: # # source ~/klammertext.zsh # # Then open a new terminal and use `ktext`, `kdesc`, `kdiag` like normal # commands. Requires Apple Silicon + macOS 26 or later, with Apple's # `container` runtime installed and its service started once by hand # (`container system start`, which sets up its kernel the first time); after # that the wrapper starts the service itself whenever it is down, as it is # after every restart. Install `container` from the signed .pkg at # https://github.com/apple/container/releases (NOT Homebrew). See # doc/install/macos_container_install.md for the full guide. # ----------------------------------------------------------------------------- # The published image is multi-arch; on Apple Silicon `container` pulls the # native arm64 build, so no --platform / --rosetta is needed. KLAMMERTEXT_IMAGE="${KLAMMERTEXT_IMAGE:-akopra/klammertext:latest}" # The container service does not survive a restart, and without it every # command fails with a connection error. So start it when it is down # (`container system status` exits 1 then) before anything needs it. _klammertext_service() { container system status >/dev/null 2>&1 \ || container system start >/dev/null 2>&1 \ || { echo "klammertext: the container service did not start; run \`container system start\` to see why" >&2; return 1; } } _klammertext_run() { local cmd="$1"; shift _klammertext_service || return 1 container run --rm \ -v "$PWD:/work" -w /work \ "$KLAMMERTEXT_IMAGE" "$cmd" "$@" } # The three Klammertext commands. Files are read from and written to the # current directory (mounted into the container as /work). ktext() { _klammertext_run ktext "$@"; } kdesc() { _klammertext_run kdesc "$@"; } kdiag() { _klammertext_run kdiag "$@"; } # Download or update to the latest published image (delete first so the moving # `latest` tag is definitely refreshed). klammertext-update() { _klammertext_service || return 1 container image delete "$KLAMMERTEXT_IMAGE" 2>/dev/null container image pull "$KLAMMERTEXT_IMAGE" }