Skip to content

Instantly share code, notes, and snippets.

@quark-zju
Last active December 8, 2016 19:09
Show Gist options
  • Select an option

  • Save quark-zju/28dbf3652935f1c1cbb8 to your computer and use it in GitHub Desktop.

Select an option

Save quark-zju/28dbf3652935f1c1cbb8 to your computer and use it in GitHub Desktop.
Use tiled view correctly
#!/usr/bin/env ruby
require 'digest'
hosts = ARGV.to_a
hosts = $<.each_line.map(&:chomp) if hosts.empty?
hosts.uniq!
def system! *args
raise "Cannot exec #{args}" unless system(*args.flatten)
end
session = "mssh-#{Digest::SHA1.hexdigest(hosts.sort.join('-'))}"
unless `tmux list-session`.include?("#{session}: ")
# new session
system! ['tmux', 'new-session', '-d', '-s', session]
system! ['tmux', 'set-option', '-t', session, 'synchronize-panes', 'off']
hosts.each do |host|
system! ['tmux', 'send-keys', '-t', session, "exec ssh #{host}", 'C-m']
if host != hosts.last
system! ['tmux', 'split-window', '-t', session]
end
system! ['tmux', 'select-layout', '-t', session, 'tiled']
end
system! ['tmux', 'set-option', '-t', session, 'synchronize-panes', 'on']
end
# attach
system! ['tmux', 'attach-session', '-t', session]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment