class Tmuxinator::ConfigWriter

Attributes

file_name[RW]
file_path[RW]
pre[RW]
project_name[RW]
project_root[RW]
rvm[RW]
tabs[RW]

Public Class Methods

new(this_full_path=nil) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 12
def initialize this_full_path=nil
  self.file_path = this_full_path if this_full_path
end
write_aliases(aliases) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 8
def self.write_aliases aliases
  File.open("#{ENV["HOME"]}/.tmuxinator/scripts/tmuxinator", 'w') {|f| f.write(aliases.join("\n")) }
end

Public Instance Methods

config_path() click to toggle source
# File lib/tmuxinator/config_writer.rb, line 30
def config_path
  "#{root_dir}#{file_name}.tmux" if file_name
end
file_path=(full_path) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 16
def file_path= full_path
  @file_path = full_path
  @file_name = File.basename full_path, '.yml'
  process_config! if full_path && File.exist?(full_path)
end
write!() click to toggle source
# File lib/tmuxinator/config_writer.rb, line 22
def write!
  raise "Unable to write with out a file_name defined" unless self.file_name
  erb         = ERB.new(IO.read(TMUX_TEMPLATE)).result(binding)
  tmp         = File.open(config_path, 'w') {|f| f.write(erb) }

  "alias start_#{file_name}='$SHELL #{config_path}'"
end

Private Instance Methods

build_command(value) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 92
def build_command(value)
  commands = [value].flatten.compact.reject { |c| c.strip.empty? }
  if @rvm
    commands.unshift "rvm use #{@rvm}"
  end

  commands.join ' && '
end
parse_tabs(tab_list) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 71
def parse_tabs tab_list
end
process_config!() click to toggle source
# File lib/tmuxinator/config_writer.rb, line 40
def process_config!
  yaml = YAML.load(File.read(file_path))

  exit!("Your configuration file should include some tabs.")        if yaml["tabs"].nil?
  exit!("Your configuration file didn't specify a 'project_root'")  if yaml["project_root"].nil?
  exit!("Your configuration file didn't specify a 'project_name'")  if yaml["project_name"].nil?

  @project_name = yaml["project_name"]
  @project_root = yaml["project_root"]
  @rvm          = yaml["rvm"]
  @pre          = build_command(yaml["pre"])
  @tabs         = []

  yaml["tabs"].each do |tab|
    t       = OpenStruct.new
    t.name  = tab.keys.first
    value   = tab.values.first

    case value
    when Hash
      t.panes = (value["panes"] || ['']).map do |pane|
        build_command(pane)
      end
      t.layout = value["layout"]
    else
      t.command = build_command(value)
    end
    @tabs << t
  end
end
root_dir() click to toggle source
# File lib/tmuxinator/config_writer.rb, line 36
def root_dir
  "#{ENV["HOME"]}/.tmuxinator/"
end
s(str)
Alias for: shell_escape
send_keys(cmd, window_number) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 87
def send_keys cmd, window_number
  return '' unless cmd
  "tmux send-keys -t #{window(window_number)} #{s cmd} C-m"
end
shell_escape(str) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 78
def shell_escape str
  "'#{str.to_s.gsub("'") { %('\'') }}'"
end
Also aliased as: s
window(i) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 83
def window(i)
  "#{s @project_name}:#{i}"
end
write_alias(stuff) click to toggle source
# File lib/tmuxinator/config_writer.rb, line 74
def write_alias stuff
  File.open("#{root_dir}scripts/#{@filename}", 'w') {|f| f.write(stuff) }
end