Files
shawnpana__smux/scripts/toggle-fullscreen
Shawn Pana cd26d2d87b Option+Escape leaves fullscreen; re-tile the origin window on join
Teach toggle-fullscreen a second mode, 'exit', that only performs the
un-fullscreen branch and never breaks a pane out. Bind Option+Escape
(M-Escape) to that mode so the key is a pure "leave fullscreen if
you're in one" — no-op on a pane that isn't currently fullscreened, no
risk of surprising the user into fullscreen. Both keys also now call
smart-layout on the pane's newly-joined window after join-pane, so
returning a pane to a two-pane layout reshapes into whichever tiling
best fits the window shape.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 14:01:58 -07:00

31 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Toggle fullscreen on a tmux pane.
# Usage: toggle-fullscreen <pane_id> [exit]
# default: toggle
# exit: only leave fullscreen (no-op if not fullscreened)
set -u
PANE="${1:-}"
MODE="${2:-toggle}"
[ -z "$PANE" ] && exit 0
IFS='|' read -r ORIG WIN NPANES <<<"$(
tmux display-message -p -t "$PANE" '#{@orig-window}|#{window_id}|#{window_panes}' 2>/dev/null
)"
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
if [ -n "$ORIG" ] && [ "$ORIG" != "$WIN" ]; then
# Stash points at a different window: return there.
if tmux list-windows -a -F '#{window_id}' 2>/dev/null | grep -qx "$ORIG"; then
tmux join-pane -s "$PANE" -t "$ORIG"
# Re-tile the origin window so the returned pane fits the layout nicely.
"$SELF_DIR/smart-layout" "$PANE" 2>/dev/null || true
fi
tmux set-option -pu -t "$PANE" @orig-window
elif [ "$MODE" = "toggle" ] && [ "${NPANES:-1}" -gt 1 ]; then
# Not currently fullscreen (or stash was stale): break out.
tmux set-option -p -t "$PANE" @orig-window "$WIN"
tmux break-pane -s "$PANE"
fi