From 642973f70bbed018e456a88e259e3ff7e8094cc5 Mon Sep 17 00:00:00 2001 From: Matt Anderson Date: Fri, 14 Aug 2026 10:32:31 -0500 Subject: [PATCH] add tmux zen mode --- tmux/.config/tmux/scripts/tmux-zen.sh | 71 +++++++++++++++++++++++++++ tmux/.tmux.conf | 2 + 2 files changed, 73 insertions(+) create mode 100755 tmux/.config/tmux/scripts/tmux-zen.sh diff --git a/tmux/.config/tmux/scripts/tmux-zen.sh b/tmux/.config/tmux/scripts/tmux-zen.sh new file mode 100755 index 0000000..c7c6326 --- /dev/null +++ b/tmux/.config/tmux/scripts/tmux-zen.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# Tmux Zen Mode - Center your terminal +# Usage: tmux-zen.sh [width] + +CENTER_WIDTH="${1:-120}" + +CURRENT_PANE=$(tmux display-message -p '#{pane_id}') +PANE_COUNT=$(tmux display-message -p '#{window_panes}') +WINDOW_WIDTH=$(tmux display-message -p '#{window_width}') + +# Check if we're already in zen mode +is_zen_mode() { + [ "$PANE_COUNT" -eq 3 ] +} + +create_zen() { + if is_zen_mode; then + return + fi + + if [ "$PANE_COUNT" -ne 1 ]; then + tmux display-message "Zen mode: single pane only" + return + fi + + TOTAL_MARGIN=$((WINDOW_WIDTH - CENTER_WIDTH - 2)) + if [ "$TOTAL_MARGIN" -lt 10 ]; then + tmux display-message "Zen mode: window too narrow" + return + fi + + SIDE_WIDTH=$((TOTAL_MARGIN / 2)) + + tmux split-window -hdt "$CURRENT_PANE" "cat" + tmux split-window -hbdt "$CURRENT_PANE" "cat" + + tmux select-layout even-horizontal + tmux resize-pane -t "$CURRENT_PANE" -x "$CENTER_WIDTH" + + for pane in $(tmux list-panes -F '#{pane_id}'); do + if [ "$pane" != "$CURRENT_PANE" ]; then + pane_command=$(tmux display-message -p -t "$pane" '#{pane_current_command}') + if [ "$pane_command" = "cat" ]; then + tmux resize-pane -t "$pane" -x "$SIDE_WIDTH" + fi + fi + done +} + +destroy_zen() { + if ! is_zen_mode; then + return + fi + + for pane in $(tmux list-panes -F '#{pane_id}'); do + pane_command=$(tmux display-message -p -t "$pane" '#{pane_current_command}') + if [ "$pane_command" = "cat" ]; then + tmux kill-pane -t "$pane" + fi + done +} + +toggle_zen() { + if is_zen_mode; then + destroy_zen + else + create_zen + fi +} + +toggle_zen diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf index a97a1bc..14e6f31 100644 --- a/tmux/.tmux.conf +++ b/tmux/.tmux.conf @@ -77,3 +77,5 @@ bind -T off-prefix O \ bind -T off-prefix Any \ send-keys C-Space \;\ send-keys + +bind z run-shell "~/.config/tmux/scripts/tmux-zen.sh 120"