class Tmuxinator::Project
Constants
- CLIARGS_DEP_MSG
- POST_DEP_MSG
- PRE_DEP_MSG
- RBENVRVM_DEP_MSG
- SYNC_DEP_MSG
- TABS_DEP_MSG
Attributes
custom_name[R]
force_attach[R]
force_detach[R]
yaml[R]
Public Class Methods
load(path, options = {})
click to toggle source
# File lib/tmuxinator/project.rb, line 42 def self.load(path, options = {}) yaml = begin raw_content = File.read(path) args = options[:args] || [] @settings = parse_settings(args) @args = args content = Erubis::Eruby.new(raw_content).result(binding) YAML.safe_load(content, aliases: true) rescue SyntaxError, StandardError => error raise "Failed to parse config file: #{error.message}" end new(yaml, options) end
new(yaml, options = {})
click to toggle source
# File lib/tmuxinator/project.rb, line 79 def initialize(yaml, options = {}) options[:force_attach] = false if options[:force_attach].nil? options[:force_detach] = false if options[:force_detach].nil? @yaml = yaml @custom_name = options[:custom_name] @force_attach = options[:force_attach] @force_detach = options[:force_detach] raise "Cannot force_attach and force_detach at the same time" \ if @force_attach && @force_detach extend Tmuxinator::WemuxSupport if wemux? end
parse_settings(args)
click to toggle source
# File lib/tmuxinator/project.rb, line 59 def self.parse_settings(args) settings = args.select { |x| x.match(/.*=.*/) } args.reject! { |x| x.match(/.*=.*/) } settings.map! do |setting| parts = setting.split("=") [parts[0], parts[1]] end Hash[settings] end
render_template(template, bndg)
click to toggle source
# File lib/tmuxinator/project.rb, line 104 def self.render_template(template, bndg) content = File.read(template) Erubis::Eruby.new(content).result(bndg) end
Public Instance Methods
attach?()
click to toggle source
# File lib/tmuxinator/project.rb, line 132 def attach? yaml_attach = if yaml["attach"].nil? true else yaml["attach"] end attach = force_attach || !force_detach && yaml_attach attach end
base_index()
click to toggle source
# File lib/tmuxinator/project.rb, line 210 def base_index get_base_index.to_i end
cli_args?()
click to toggle source
# File lib/tmuxinator/project.rb, line 304 def cli_args? yaml["cli_args"] end
deprecation_checks()
click to toggle source
# File lib/tmuxinator/project.rb, line 266 def deprecation_checks [ rvm_or_rbenv?, tabs?, cli_args?, legacy_synchronize?, pre?, post? ] end
deprecation_messages()
click to toggle source
# File lib/tmuxinator/project.rb, line 277 def deprecation_messages [ RBENVRVM_DEP_MSG, TABS_DEP_MSG, CLIARGS_DEP_MSG, SYNC_DEP_MSG, PRE_DEP_MSG, POST_DEP_MSG ] end
deprecations()
click to toggle source
# File lib/tmuxinator/project.rb, line 258 def deprecations deprecation_checks.zip(deprecation_messages). inject([]) do |deps, (chk, msg)| deps << msg if chk deps end end
get_base_index()
click to toggle source
# File lib/tmuxinator/project.rb, line 320 def get_base_index tmux_config["base-index"] end
get_pane_base_index()
click to toggle source
# File lib/tmuxinator/project.rb, line 316 def get_pane_base_index tmux_config["pane-base-index"] end
kill()
click to toggle source
# File lib/tmuxinator/project.rb, line 100 def kill self.class.render_template(Tmuxinator::Config.stop_template, binding) end
name()
click to toggle source
# File lib/tmuxinator/project.rb, line 122 def name name = custom_name || yaml["project_name"] || yaml["name"] blank?(name) ? nil : name.to_s.shellescape end
name?()
click to toggle source
# File lib/tmuxinator/project.rb, line 238 def name? !name.nil? end
pane_base_index()
click to toggle source
# File lib/tmuxinator/project.rb, line 214 def pane_base_index get_pane_base_index.to_i end
post()
click to toggle source
# File lib/tmuxinator/project.rb, line 155 def post post_config = yaml["post"] parsed_parameters(post_config) end
post?()
click to toggle source
# File lib/tmuxinator/project.rb, line 312 def post? yaml["post"] end
pre()
click to toggle source
# File lib/tmuxinator/project.rb, line 127 def pre pre_config = yaml["pre"] parsed_parameters(pre_config) end
pre?()
click to toggle source
# File lib/tmuxinator/project.rb, line 308 def pre? yaml["pre"] end
pre_window()
click to toggle source
# File lib/tmuxinator/project.rb, line 142 def pre_window params = if rbenv? "rbenv shell #{yaml['rbenv']}" elsif rvm? "rvm use #{yaml['rvm']}" elsif pre_tab? yaml["pre_tab"] else yaml["pre_window"] end parsed_parameters(params) end
rbenv?()
click to toggle source
# File lib/tmuxinator/project.rb, line 288 def rbenv? yaml["rbenv"] end
render()
click to toggle source
# File lib/tmuxinator/project.rb, line 96 def render self.class.render_template(Tmuxinator::Config.template, binding) end
root()
click to toggle source
# File lib/tmuxinator/project.rb, line 117 def root root = yaml["project_root"] || yaml["root"] blank?(root) ? nil : File.expand_path(root).shellescape end
root?()
click to toggle source
# File lib/tmuxinator/project.rb, line 234 def root? !root.nil? end
rvm?()
click to toggle source
# File lib/tmuxinator/project.rb, line 292 def rvm? yaml["rvm"] end
rvm_or_rbenv?()
click to toggle source
# File lib/tmuxinator/project.rb, line 296 def rvm_or_rbenv? rvm? || rbenv? end
send_keys(cmd, window_index)
click to toggle source
# File lib/tmuxinator/project.rb, line 250 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 246 def send_pane_command(cmd, window_index, _pane_index) send_keys(cmd, window_index) end
show_tmux_options()
click to toggle source
# File lib/tmuxinator/project.rb, line 324 def show_tmux_options "#{tmux} start-server\\; " \ "show-option -g base-index\\; " \ "show-window-option -g pane-base-index\\;" end
socket()
click to toggle source
# File lib/tmuxinator/project.rb, line 184 def socket if socket_path " -S #{socket_path}" elsif socket_name " -L #{socket_name}" end end
socket_name()
click to toggle source
# File lib/tmuxinator/project.rb, line 192 def socket_name yaml["socket_name"] end
socket_path()
click to toggle source
# File lib/tmuxinator/project.rb, line 196 def socket_path yaml["socket_path"] end
startup_pane()
click to toggle source
# File lib/tmuxinator/project.rb, line 222 def startup_pane "#{startup_window}.#{yaml['startup_pane'] || pane_base_index}" end
startup_window()
click to toggle source
# File lib/tmuxinator/project.rb, line 218 def startup_window "#{name}:#{yaml['startup_window'] || base_index}" end
tabs?()
click to toggle source
# File lib/tmuxinator/project.rb, line 300 def tabs? yaml["tabs"] end
tmux()
click to toggle source
# File lib/tmuxinator/project.rb, line 160 def tmux "#{tmux_command}#{tmux_options}#{socket}" end
tmux_command()
click to toggle source
# File lib/tmuxinator/project.rb, line 164 def tmux_command yaml["tmux_command"] || "tmux" end
tmux_has_session?(name)
click to toggle source
# File lib/tmuxinator/project.rb, line 168 def tmux_has_session?(name) # Redirect stderr to /dev/null in order to prevent "failed to connect # to server: Connection refused" error message and non-zero exit status # if no tmux sessions exist. # Please see issues #402 and #414. sessions = `#{tmux} ls 2> /dev/null` # Remove any escape sequences added by `shellescape` in Project#name. # Escapes can result in: "ArgumentError: invalid multibyte character" # when attempting to match `name` against `sessions`. # Please see issue #564. unescaped_name = name.shellsplit.join("") !(sessions !~ /^#{unescaped_name}:/) end
tmux_kill_session_command()
click to toggle source
# File lib/tmuxinator/project.rb, line 335 def tmux_kill_session_command "#{tmux} kill-session -t #{name}" end
tmux_new_session_command()
click to toggle source
# File lib/tmuxinator/project.rb, line 330 def tmux_new_session_command window = windows.first.tmux_window_name_option "#{tmux} new-session -d -s #{name} #{window}" end
tmux_options()
click to toggle source
# File lib/tmuxinator/project.rb, line 200 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 226 def tmux_options? yaml["tmux_options"] end
validate!()
click to toggle source
# File lib/tmuxinator/project.rb, line 71 def validate! raise "Your project file should include some windows." \ unless windows? raise "Your project file didn't specify a 'project_name'" \ unless name? self end
window(i)
click to toggle source
# File lib/tmuxinator/project.rb, line 242 def window(i) "#{name}:#{i}" end
windows()
click to toggle source
# File lib/tmuxinator/project.rb, line 109 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 230 def windows? windows.any? end
Private Instance Methods
blank?(object)
click to toggle source
# File lib/tmuxinator/project.rb, line 341 def blank?(object) (object.respond_to?(:empty?) && object.empty?) || !object end
extract_tmux_config()
click to toggle source
# File lib/tmuxinator/project.rb, line 349 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
legacy_synchronize?()
click to toggle source
# File lib/tmuxinator/project.rb, line 363 def legacy_synchronize? (synchronize_options & [true, "before"]).any? end
parsed_parameters(parameters)
click to toggle source
# File lib/tmuxinator/project.rb, line 377 def parsed_parameters(parameters) parameters.is_a?(Array) ? parameters.join("; ") : parameters end
synchronize_options()
click to toggle source
# File lib/tmuxinator/project.rb, line 367 def synchronize_options window_options.map do |option| option["synchronize"] if option.is_a?(Hash) end end
tmux_config()
click to toggle source
# File lib/tmuxinator/project.rb, line 345 def tmux_config @tmux_config ||= extract_tmux_config end
wemux?()
click to toggle source
# File lib/tmuxinator/project.rb, line 381 def wemux? yaml["tmux_command"] == "wemux" end
window_options()
click to toggle source
# File lib/tmuxinator/project.rb, line 373 def window_options yaml["windows"].map(&:values).flatten end