class Threeman::Frontends::Tmux

Attributes

session[R]

Public Class Methods

new(options) click to toggle source
Calls superclass method Threeman::Frontend::new
# File lib/threeman/frontends/tmux.rb, line 8
def initialize(options)
  @session = "threeman_#{Time.now.to_i}"
  super
end

Public Instance Methods

run_commands(commands) click to toggle source
# File lib/threeman/frontends/tmux.rb, line 13
def run_commands(commands)
  sort_commands(commands).each_with_index do |command, index|
    run_command(command, index)
  end

  system "tmux attach-session -t #{session}"
end

Private Instance Methods

layout_name() click to toggle source
# File lib/threeman/frontends/tmux.rb, line 37
def layout_name
  options[:layout_name] || 'tiled'
end
run_command(command, index) click to toggle source
# File lib/threeman/frontends/tmux.rb, line 22
def run_command(command, index)
  bash_cmd = "bash -c #{Shellwords.escape bash_script(command)}"

  name_opt = "-n #{Shellwords.escape command.name}"
  common_opts = "-c #{Shellwords.escape command.workdir} #{Shellwords.escape bash_cmd}"
  if index == 0
    system "tmux new-session -d -s #{session} #{name_opt} #{common_opts}"
  elsif paned_command_names.include?(command.name)
    system "tmux split-window -v -d -f -t #{session}:0.#{index - 1} #{common_opts}"
    system "tmux select-layout -t #{session}:0 #{layout_name}"
  else
    system "tmux -v new-window -t #{session}:#{index} #{name_opt} #{common_opts}"
  end
end