Temporarily zooming panes in tmux

Suraj N. Kurapati

  1. Problem
    1. Approach
      1. Solution


        In my wmii configuration, I often use the “client zoom” feature where a group of selected clients (or just the currently focused client if there is no selection) is zoomed onto a temporary view. This allows me to focus on the task at hand while also giving more space to the client(s) that are relevant to that task.


        I ported that feature to tmux this evening, as shown below, by enhancing an existing snippet, which was written by an anonymous user known only as “akshay”, in the following ways:


        bind -n M-m run 'set -e;                                            \
          new_ip=$(tmux display-message -p "#I|#P");                        \
          if ! tmux select-window -t "*$new_ip"; then                       \
            old_wip=$(tmux display-message -p "#W");                        \
            old_w=${old_wip%|[0-9]*|[0-9]*};                                \
            if test "$old_w" != "$old_wip"; then                            \
              old_i=${old_wip%|*}; old_i=${old_i##*|};                      \
              old_p=${old_wip##*|};                                         \
              cur_i=$(tmux display-message -p "#I");                        \
              cur_p=$(tmux display-message -p "#P");                        \
              tmux select-window -t ":$old_i";                              \
              tmux select-pane -t ":$old_i.$old_p";                         \
              tmux swap-pane -s ":$cur_i.$cur_p";                           \
              if test "$(tmux list-panes -t ":$cur_i" | wc -l)" -le 1; then \
                tmux kill-window -t ":$cur_i";                              \
              fi;                                                           \
            else                                                            \
              new_wip="$old_wip|$new_ip";                                   \
              tmux new-window -d -n "$new_wip" "sh -c \"                    \
                trap : INT QUIT;                                            \
                while :; do                                                 \
                  echo PLACEHOLDER;                                         \
                  cat > /dev/null;                                          \
                done                                                        \
              \"";                                                          \
              tmux swap-pane -s "$new_wip";                                 \
              tmux select-window -t "$new_wip";                             \
            fi;                                                             \
          fi;                                                               \