#!/usr/bin/env bash # Build, install and hot-reload the pane-finder plugin. # # Lives in the sl0ppij (zellij fork) checkout and path-depends on its # zellij-tile, so the plugin API always matches the binary built beside it. # # NOTE: zellij caches a plugin's compiled module in the *server's memory*, keyed # by plugin path, for the lifetime of the session. Overwriting the .wasm on disk # and re-launching (even after closing the pane) keeps running the OLD build. # Only `start-or-reload-plugin` (or a brand new session) picks up a new build, # which is why this script does it for every running session. set -euo pipefail SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DEST="$HOME/.config/zellij/plugins/pane-finder.wasm" URL="file:$DEST" cd "$SRC_DIR" cargo build --release --target wasm32-wasip1 # NOT "$SRC_DIR/target": the zellij checkout's .cargo/config.toml sets a shared # build.target-dir, so artifacts land in the repo's target dir rather than this # crate's. Ask cargo where they actually went instead of guessing. TARGET_DIR="$(cargo metadata --format-version 1 --no-deps \ | python3 -c 'import json,sys; print(json.load(sys.stdin)["target_directory"])')" WASM="$TARGET_DIR/wasm32-wasip1/release/zj-pane-finder.wasm" [ -f "$WASM" ] || { echo "build produced no wasm at $WASM" >&2; exit 1; } mkdir -p "$(dirname "$DEST")" cp "$WASM" "$DEST" echo "installed -> $DEST" # hot-reload in every live session # `--short` also lists dead sessions, so parse the long form and drop EXITED ones mapfile -t sessions < <(zellij list-sessions 2>/dev/null \ | sed 's/\x1b\[[0-9;]*m//g' \ | grep -v EXITED \ | awk 'NF {print $1}' || true) if [ "${#sessions[@]}" -eq 0 ]; then echo "no running sessions; new sessions will pick this up automatically" exit 0 fi for s in "${sessions[@]}"; do [ -z "$s" ] && continue if zellij -s "$s" action start-or-reload-plugin "$URL" >/dev/null 2>&1; then echo "reloaded in session: $s" else echo "could not reload in session: $s (start a new session instead)" fi done