├── README.md ├── tmux-zoom.rb └── tmux-zoom.sh /README.md: -------------------------------------------------------------------------------- 1 | # Panes zooming in tmux 2 | 3 | tmux 1.8 added the -Z flag to the resize-panes command, and it binds it by default to the PREFIX z shortcut. 4 | 5 | No need for this dirty hack anymore! 6 | -------------------------------------------------------------------------------- /tmux-zoom.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | current = `tmux display-message -p '#W-#I-#P' \\; list-window` 4 | current.match /^(.*)-(\d+)-(\d+)\n/ 5 | current_window = $1 6 | current_pane = "#{$2}-#{$3}" 7 | new_zoom_window = "ZOOM-#{current_pane}" 8 | listado = current 9 | 10 | if current_window.match /^ZOOM-(\d+)-(\d+)$/ 11 | old_zoom_window = "ZOOM-#{$1}-#{$2}" 12 | `tmux select-window -t #{$1} \\; select-pane -t #{$2} \\; swap-pane -s #{old_zoom_window}.1 \\; kill-window -t #{old_zoom_window}` 13 | elsif listado.match new_zoom_window 14 | `tmux select-window -t #{new_zoom_window}` 15 | else 16 | `tmux new-window -d -n #{new_zoom_window} \\; swap-pane -s #{new_zoom_window}.1 \\; select-window -t #{new_zoom_window}` 17 | end -------------------------------------------------------------------------------- /tmux-zoom.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) 2012 Juan Ignacio Pumarino, jipumarino@gmail.com 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining 6 | # a copy of this software and associated documentation files (the 7 | # "Software"), to deal in the Software without restriction, including 8 | # without limitation the rights to use, copy, modify, merge, publish, 9 | # distribute, sublicense, and/or sell copies of the Software, and to 10 | # permit persons to whom the Software is furnished to do so, subject to 11 | # the following conditions: 12 | # 13 | # The above copyright notice and this permission notice shall be 14 | # included in all copies or substantial portions of the Software. 15 | # 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | # Instructions 25 | # ------------ 26 | # 27 | # 1. Install this script and give it execute permission somewhere in your PATH. 28 | # For example: 29 | # 30 | # $ mkdir -p ~/bin 31 | # $ wget https://raw.github.com/jipumarino/tmux-zoom/master/tmux-zoom.sh -O ~/bin/tmux-zoom.sh 32 | # $ chmod +x ~/bin/tmux-zoom.sh 33 | # 34 | # 2. Add a shortcut in your ~/.tmux.conf file: 35 | # 36 | # bind C-k run "tmux-zoom.sh" 37 | # 38 | # 3. When using this shortcut, the current tmux pane will open in a new window by itself. 39 | # Running it again in the zoomed window will return it to its original pane. You can have 40 | # as many zoomed windows as you want. 41 | 42 | current=$(tmux display-message -p '#W-#I-#P') 43 | list=$(tmux list-window) 44 | 45 | [[ "$current" =~ ^(.*)-([0-9]+)-([0-9]+) ]] 46 | current_window=${BASH_REMATCH[1]} 47 | current_pane=${BASH_REMATCH[2]}-${BASH_REMATCH[3]} 48 | new_zoom_window=ZOOM-$current_pane 49 | 50 | if [[ $current_window =~ ZOOM-([0-9]+)-([0-9+]) ]]; then 51 | if [ "$(tmux list-panes | wc -l)" -gt 1 ]; then 52 | tmux display-message "other panes exist" 53 | exit 0 54 | fi 55 | old_zoom_window=ZOOM-${BASH_REMATCH[1]}-${BASH_REMATCH[2]} 56 | tmux select-window -t ${BASH_REMATCH[1]} \; select-pane -t ${BASH_REMATCH[2]} \; swap-pane -s $old_zoom_window.0 \; kill-window -t $old_zoom_window 57 | elif [[ $list =~ $new_zoom_window ]]; then 58 | tmux select-window -t $new_zoom_window 59 | else 60 | if [ "$(tmux list-panes | wc -l)" -eq 1 ]; then 61 | tmux display-message "already zoomed" 62 | exit 0 63 | fi 64 | tmux new-window -d -n $new_zoom_window \; swap-pane -s $new_zoom_window.0 \; select-window -t $new_zoom_window 65 | fi 66 | --------------------------------------------------------------------------------