Skip to content

Instantly share code, notes, and snippets.

@ThomasAdam
Forked from pi8027/README.mkd
Created November 5, 2012 18:57
Show Gist options
  • Save ThomasAdam/4019584 to your computer and use it in GitHub Desktop.
Save ThomasAdam/4019584 to your computer and use it in GitHub Desktop.

pane-maximize

Maximize and restore panes in tmux 1.7. (incompatible with <=1.6)

installation

  1. Copy pane-maximize* from here to ~/bin/ directory.

  2. Add a key binding to .tmux.conf:

    bind-key m run-shell "pane-maximize -a"

#!/bin/bash
# By Kazuhiko Sakaguchi. Public domain.
function usage_exit(){
cat <<EOT
Usage: $(echo $0 | sed "s/.*\///") [-adP] [-F format] [-t target-pane]
-a, -d, -P, -F format: these options are passed to tmux new-window
-t target-pane: specify target pane
EOT
exit $1
}
paneid=$(tmux display-message -p '#{pane_id}')
optflag_a=false
nwopts=
while getopts adPF:t: OPT ; do
case $OPT in
t ) paneid=$OPTARG ;;
a ) optflag_a=true ;;
d|P) nwopts="-$OPT $nwopts" ;;
F ) nwopts="-F $OPTARG $nwopts" ;;
* ) usage_exit -1 ;;
esac
done
paneid=$(tmux display-message -t $paneid -p '#{pane_id}' || exit -1)
winid=$(tmux display-message -t $paneid -p '#{window_id}')
pmtable=$(tmux showenv pmtable | sed 's/^pmtable=//')
$optflag_a && nwopts="-a -t $winid $nwopts"
if target=$(echo $pmtable | tr : "\n" | \
grep -E "(=|^)$paneid(=|$)" | head -n 1 | grep .) ; then
IFS== ; set -- $target ; IFS=' ' ; \
tmux swap-pane -t $2 -s $1 \; \
kill-pane -t $2 \; \
setenv pmtable "$(echo $pmtable | sed "s/:$target//")"
elif [ $(tmux list-panes -t $winid -F '' | wc -l) != 1 ] ; then
echo $nwopts
tmux new-window $nwopts "\"$0-sub\" $paneid"
fi
#!/bin/bash
# By Kazuhiko Sakaguchi. Public domain.
pmtable=$(tmux showenv pmtable | sed 's/^pmtable=//')
tmux swap-pane -s $1 -t $TMUX_PANE \; \
setenv pmtable "$pmtable:$1=$TMUX_PANE"
echo -ne '\033]2;DUMMY PANE\033\\'
stty intr undef
echo '********************'
echo '**** dummy pane ****'
echo '********************'
while true ; do read ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment