class Tmuxinator::Project

Attributes

custom_name[R]
yaml[R]

Public Class Methods

new(yaml, custom_name = nil) click to toggle source
# File lib/tmuxinator/project.rb, line 9
def initialize(yaml, custom_name = nil)
  @yaml = yaml
  @custom_name = custom_name
  load_wemux_overrides if wemux?
end

Public Instance Methods

attach() click to toggle source
# File lib/tmuxinator/project.rb, line 59
def attach
  attach = true
  if !yaml["attach"].nil?
    attach = yaml["attach"]
  end
  attach
end
attach?() click to toggle source
# File lib/tmuxinator/project.rb, line 136
def attach?
  !!attach
end
base_index() click to toggle source
# File lib/tmuxinator/project.rb, line 112
def base_index
  get_pane_base_index ? get_pane_base_index.to_i : get_base_index.to_i
end
deprecations() click to toggle source
# File lib/tmuxinator/project.rb, line 160
def deprecations
  deprecations = []
  deprecations << "DEPRECATION: rbenv/rvm specific options have been replaced by the pre_tab option and will not be supported in 0.8.0." if yaml["rbenv"] || yaml["rvm"]
  deprecations << "DEPRECATION: The tabs option has been replaced by the windows option and will not be supported in 0.8.0." if yaml["tabs"]
  deprecations << "DEPRECATION: The cli_args option has been replaced by the tmux_options option and will not be supported in 0.8.0." if yaml["cli_args"]
  deprecations
end
get_base_index() click to toggle source
# File lib/tmuxinator/project.rb, line 172
def get_base_index
  tmux_config["base-index"]
end
get_pane_base_index() click to toggle source
# File lib/tmuxinator/project.rb, line 168
def get_pane_base_index
  tmux_config["pane-base-index"]
end
name() click to toggle source
# File lib/tmuxinator/project.rb, line 33
def name
  name = custom_name || yaml["project_name"] || yaml["name"]
  name.blank? ? nil : name.shellescape
end
name?() click to toggle source
# File lib/tmuxinator/project.rb, line 132
def name?
  !name.nil?
end
post() click to toggle source
# File lib/tmuxinator/project.rb, line 67
def post
  post_config = yaml["post"]
  if post_config.is_a?(Array)
    post_config.join("; ")
  else
    post_config
  end
end
pre() click to toggle source
# File lib/tmuxinator/project.rb, line 38
def pre
  pre_config = yaml["pre"]
  if pre_config.is_a?(Array)
    pre_config.join("; ")
  else
    pre_config
  end
end
pre_window() click to toggle source
# File lib/tmuxinator/project.rb, line 47
def pre_window
  if rbenv?
    "rbenv shell #{yaml["rbenv"]}"
  elsif rvm?
    "rvm use #{yaml["rvm"]}"
  elsif pre_tab?
    yaml["pre_tab"]
  else
    yaml["pre_window"]
  end
end
render() click to toggle source
# File lib/tmuxinator/project.rb, line 15
def render
  template = File.read(Tmuxinator::Config.template)
  Erubis::Eruby.new(template).result(binding)
end
root() click to toggle source
# File lib/tmuxinator/project.rb, line 28
def root
  root = yaml["project_root"] || yaml["root"]
  root.blank? ? nil : File.expand_path(root).shellescape
end
root?() click to toggle source
# File lib/tmuxinator/project.rb, line 128
def root?
  !root.nil?
end
send_keys(cmd, window_index) click to toggle source
# File lib/tmuxinator/project.rb, line 152
def send_keys(cmd, window_index)
  if cmd.empty?
   ""
  else
    "#{tmux} send-keys -t #{window(window_index)} #{cmd.shellescape} C-m"
  end
end
send_pane_command(cmd, window_index, pane_index) click to toggle source
# File lib/tmuxinator/project.rb, line 144
def send_pane_command(cmd, window_index, pane_index)
  if cmd.empty?
    ""
  else
    "#{tmux} send-keys -t #{window(window_index)} #{cmd.shellescape} C-m"
  end
end
show_tmux_options() click to toggle source
# File lib/tmuxinator/project.rb, line 176
def show_tmux_options
  "#{tmux} start-server\\; show-option -g"
end
socket() click to toggle source
# File lib/tmuxinator/project.rb, line 84
def socket
  if socket_path
    " -S #{socket_path}"
  elsif socket_name
    " -L #{socket_name}"
  else
    nil
  end
end
socket_name() click to toggle source
# File lib/tmuxinator/project.rb, line 94
def socket_name
  yaml["socket_name"]
end
socket_path() click to toggle source
# File lib/tmuxinator/project.rb, line 98
def socket_path
  yaml["socket_path"]
end
startup_window() click to toggle source
# File lib/tmuxinator/project.rb, line 116
def startup_window
  yaml["startup_window"] || base_index
end
tmux() click to toggle source
# File lib/tmuxinator/project.rb, line 76
def tmux
  "#{tmux_command}#{tmux_options}#{socket}"
end
tmux_command() click to toggle source
# File lib/tmuxinator/project.rb, line 80
def tmux_command
  yaml["tmux_command"] || "tmux"
end
tmux_options() click to toggle source
# File lib/tmuxinator/project.rb, line 102
def tmux_options
  if cli_args?
    " #{yaml["cli_args"].to_s.strip}"
  elsif tmux_options?
    " #{yaml["tmux_options"].to_s.strip}"
  else
    ""
  end
end
tmux_options?() click to toggle source
# File lib/tmuxinator/project.rb, line 120
def tmux_options?
  yaml["tmux_options"]
end
window(i) click to toggle source
# File lib/tmuxinator/project.rb, line 140
def window(i)
  "#{name}:#{i}"
end
windows() click to toggle source
# File lib/tmuxinator/project.rb, line 20
def windows
  windows_yml = yaml["tabs"] || yaml["windows"]

  @windows ||= windows_yml.map.with_index do |window_yml, index|
    Tmuxinator::Window.new(window_yml, index, self)
  end
end
windows?() click to toggle source
# File lib/tmuxinator/project.rb, line 124
def windows?
  windows.any?
end

Private Instance Methods

extract_tmux_config() click to toggle source
# File lib/tmuxinator/project.rb, line 186
def extract_tmux_config
  options_hash = {}

  options_string = `#{show_tmux_options}`
  options_string.encode!("UTF-8", :invalid => :replace)
  options_string.split("\n").map do |entry|
    key, value = entry.split("\s")
    options_hash[key] = value
    options_hash
  end

  options_hash
end
tmux_config() click to toggle source
# File lib/tmuxinator/project.rb, line 182
def tmux_config
  @tmux_config ||= extract_tmux_config
end