Skip to content

Instantly share code, notes, and snippets.

@opennomad
Created July 25, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opennomad/ffbab2393b3d166d6148f20e5a011034 to your computer and use it in GitHub Desktop.
Save opennomad/ffbab2393b3d166d6148f20e5a011034 to your computer and use it in GitHub Desktop.
Script to toggle the vertical size of current tmux pane to maximum
#!/usr/bin/env bash
#
# author: matthias@opennomad.com
# inspiration from https://www.reddit.com/r/tmux/comments/7r8otc/is_there_short_command_to_expansetoggle_tmux_pane/
#
# This script toggles the vertical size of the current tmux pane to maximum
# Note that the other panes in the same column will still be visible, but
# they will be only one line tall.
#
# Installation:
# Save the script as `tmux-vertical-toggle.sh` and make it executable.
# Then bind this in tmux to (for example) a capital Z
# and make sure to change the path to your chosen install path.
#
### bind-key 'Z' run "~/bin/tmux-vertical-toggle.sh"
#
# we need a statefile to bind this to a key in tmux
# feel free to change this
TMUX_VERTICAL_STATE_FILE="${HOME}/.tmux-vertical"
if [[ -f "${TMUX_VERTICAL_STATE_FILE}" ]]; then
# read the layout from the state file
TMVertLayout=$(<${TMUX_VERTICAL_STATE_FILE})
# come back to the previous layout
tmux select-layout "$TMVertLayout"
# remove the state file
rm ${TMUX_VERTICAL_STATE_FILE}
else
# save the current layout
TMVertLayout=$(tmux list-windows |awk '$NF~/active/ {print $7}');
TMVertLayout=${TMVertLayout: :-1}
# write the layout to the state file
echo ${TMVertLayout} > ${TMUX_VERTICAL_STATE_FILE}
# #resize the active pane height
tmux resize-pane -y 100
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment