Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gwpl/6fdf493107c57ed6dbefdd3c9cb49d44 to your computer and use it in GitHub Desktop.
Save gwpl/6fdf493107c57ed6dbefdd3c9cb49d44 to your computer and use it in GitHub Desktop.

Robust <prefix> g Pane-Zoom Hook for Outer tmux

Whether you’re juggling multiple windows and panes across nested tmux sessions, having a single, ergonomic shortcut to switch and zoom panes can save you valuable time. This snippet extends your outer tmux configuration to bind <prefix> g for a seamless, two-step pane selection: un-zoom the current pane, display a long-lasting pane number overlay, and automatically zoom the pane you choose—all in one intuitive command.

Use this snippet in your ~/.ubertmux to bind <prefix> g so it:

  • Works whether the current pane is zoomed or not
  • Displays pane numbers overlay for up to 600 seconds (10 minutes)
  • Allows you to select any pane (including the same one) and zoom it automatically
# ~/.ubertmux

# Unbind existing 'g' binding
unbind-key g

# Bind '<prefix> g' robustly
bind-key g \
  if-shell -F '#{window_zoomed_flag}' 'resize-pane -Z' '' \; \
  display-panes -d 600000 "select-pane -t '%%'; resize-pane -Z"

How it works

  1. Conditional un-zoom

    • The if-shell -F '#{window_zoomed_flag}' 'resize-pane -Z' '' checks if the current pane is zoomed (window_zoomed_flag = 1).
    • If zoomed, it runs resize-pane -Z to un-zoom; otherwise, it does nothing.
  2. Display pane numbers

    • display-panes -d 600000 ... shows a numbered overlay for 600,000 milliseconds (600s).
    • The command following the duration is a template: when you press a pane number, tmux substitutes %% with the pane ID and runs the commands.
  3. Select and zoom

    • The template "select-pane -t '%%'; resize-pane -Z" switches to the chosen pane and immediately zooms it, even if it's the pane you were already in.

Co-created with ChatGPT o4-mini-high:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment