Skip to content

Instantly share code, notes, and snippets.

@lewang
Created March 28, 2012 15:49
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 lewang/2227539 to your computer and use it in GitHub Desktop.
Save lewang/2227539 to your computer and use it in GitHub Desktop.
tmux zoom and unzoom pane into its window. Can have multiple panex zoomed in at once
#!/usr/bin/ruby
# INSTALL:
#
# 1. Make script executable and put it in your $PATH
#
# 2. add to ~/.tmux.conf
#
# bind + run tmux-zoom
#
# 3. use <prefix-key> <+> to zoom and un-zoom
#
# require 'rubygems'; require 'ruby-debug'
WINDOW_PREFIX = 'tmux-zoom-'
window=`tmux display-message -p '#W'`.chomp!
if res = /\A#{WINDOW_PREFIX}(\d+)/.match(window)
num = res[1]
match = nil;
`tmux show-env`.each do |line|
if match = /^#{window}-origin=(.*)$/.match(line)
break
end
end
if match
original_pane = match[1]
else
system('tmux display-message "This window isn\'t really zoomed."')
exit(1)
end
original_window=original_pane.sub(/\..*?\Z/, "")
system("tmux select-pane -t #{original_pane}\\; select-window -t #{original_window}\\; swap-pane -s #{window}.0 \\; kill-window -t #{window}")
else
windows = `tmux list-windows -F "#W"`.each_line.grep(/^#{WINDOW_PREFIX}/).map(&:chomp!)
new_title = "#{WINDOW_PREFIX}#{windows.length}"
var_name = "#{new_title}-origin"
origin_pane = `tmux display-message -p "#S:#I.#P"`.chomp!
system("tmux set-env #{var_name} #{origin_pane}\\; new-window -d -n #{new_title} 'clear && echo see #{new_title} && read' \\; swap-pane -s #{new_title}.0 \\; select-window -t #{new_title}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment