class Tmuxinator::Project
Constants
- CLIARGS_DEP_MSG
- POST_DEP_MSG
- PRE_DEP_MSG
- RBENVRVM_DEP_MSG
- SYNC_DEP_MSG
- TABS_DEP_MSG
Attributes
Public Class Methods
Source
# File lib/tmuxinator/project.rb, line 72 def active Tmuxinator::Config.configs(active: true). map { |config| Config.validate(name: config) } end
Source
# File lib/tmuxinator/project.rb, line 45 def load(path, options = {}) yaml = begin args = options[:args] || [] @settings = parse_settings(args) @args = args content = render_template(path, binding) YAML.safe_load(content, aliases: true) rescue SyntaxError, StandardError => e raise "Failed to parse config file: #{e.message}" end new(yaml, options) end
Source
# File lib/tmuxinator/project.rb, line 93 def initialize(yaml, options = {}) options[:force_attach] = false if options[:force_attach].nil? options[:force_detach] = false if options[:force_detach].nil? @yaml = yaml set_instance_variables_from_options(options) validate_options extend Tmuxinator::WemuxSupport if wemux? end
Source
# File lib/tmuxinator/project.rb, line 60 def parse_settings(args) settings = args.select { |x| x.match(/.*=.*/) } args.reject! { |x| x.match(/.*=.*/) } settings.map! do |setting| parts = setting.split("=", 2) [parts[0], parts[1]] end Hash[settings] end
Source
# File lib/tmuxinator/project.rb, line 132 def self.render_template(template, bndg) content = File.read(template) bndg.eval(Erubi::Engine.new(content).src) end
Source
# File lib/tmuxinator/project.rb, line 77 def stop_all active. sort_by { |project| project.name == current_session_name ? 1 : 0 }. each { |project| Kernel.system(project.kill) } end
Public Instance Methods
Source
# File lib/tmuxinator/project.rb, line 170 def attach? yaml_attach = yaml["attach"].nil? || yaml["attach"] force_attach || !force_detach && yaml_attach end
Source
# File lib/tmuxinator/project.rb, line 255 def base_index return last_window_index + 1 if append? get_base_index.to_i end
Source
# File lib/tmuxinator/project.rb, line 320 def deprecation_checks [ rvm_or_rbenv?, tabs?, cli_args?, legacy_synchronize?, pre?, post? ] end
Source
# File lib/tmuxinator/project.rb, line 331 def deprecation_messages [ RBENVRVM_DEP_MSG, TABS_DEP_MSG, CLIARGS_DEP_MSG, SYNC_DEP_MSG, PRE_DEP_MSG, POST_DEP_MSG ] end
Source
# File lib/tmuxinator/project.rb, line 312 def deprecations deprecation_checks.zip(deprecation_messages). inject([]) do |deps, (chk, msg)| deps << msg if chk deps end end
Source
# File lib/tmuxinator/project.rb, line 395 def enable_pane_titles? yaml["enable_pane_titles"] end
Source
# File lib/tmuxinator/project.rb, line 374 def get_base_index tmux_config["base-index"] end
Source
# File lib/tmuxinator/project.rb, line 370 def get_pane_base_index tmux_config["pane-base-index"] end
Source
# File lib/tmuxinator/project.rb, line 128 def kill self.class.render_template(Tmuxinator::Config.stop_template, binding) end
Source
# File lib/tmuxinator/project.rb, line 251 def last_window_index `tmux list-windows -F '#I'`.split.last.to_i end
Source
# File lib/tmuxinator/project.rb, line 150 def name name = if append? current_session_name else custom_name || yaml["project_name"] || yaml["name"] end blank?(name) ? nil : name.to_s.tr(".:", "__").shellescape end
Source
# File lib/tmuxinator/project.rb, line 261 def pane_base_index get_pane_base_index.to_i end
Source
# File lib/tmuxinator/project.rb, line 417 def pane_title_position_not_valid_warning print_warning( "The specified pane title position '#{yaml['pane_title_position']}' " \ "is not valid. Please choose one of: top, bottom, or off." ) end
Source
# File lib/tmuxinator/project.rb, line 424 def pane_titles_not_supported_warning print_warning( "You have enabled pane titles in your configuration, but the " \ "feature is not supported by your version of tmux.\nPlease consider " \ "upgrading to a version that supports it (tmux >=2.6)." ) end
Source
# File lib/tmuxinator/project.rb, line 190 def post post_config = yaml["post"] parsed_parameters(post_config) end
Source
# File lib/tmuxinator/project.rb, line 165 def pre pre_config = yaml["pre"] parsed_parameters(pre_config) end
Source
# File lib/tmuxinator/project.rb, line 175 def pre_window return if no_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
Source
# File lib/tmuxinator/project.rb, line 124 def render self.class.render_template(Tmuxinator::Config.template, binding) end
Source
# File lib/tmuxinator/project.rb, line 145 def root root = yaml["project_root"] || yaml["root"] blank?(root) ? nil : File.expand_path(root).shellescape end
Source
# File lib/tmuxinator/project.rb, line 350 def rvm_or_rbenv? rvm? || rbenv? end
Source
# File lib/tmuxinator/project.rb, line 304 def send_keys(cmd, window_index) if cmd.empty? "" else "#{tmux} send-keys -t #{window(window_index)} #{cmd.shellescape} C-m" end end
Source
# File lib/tmuxinator/project.rb, line 300 def send_pane_command(cmd, window_index, _pane_index) send_keys(cmd, window_index) end
Source
# File lib/tmuxinator/project.rb, line 106 def set_instance_variables_from_options(options) @custom_name = options[:custom_name] @force_attach = options[:force_attach] @force_detach = options[:force_detach] @append = options[:append] @no_pre_window = options[:no_pre_window] end
Source
# File lib/tmuxinator/project.rb, line 378 def show_tmux_options "#{tmux} start-server\\; " \ "show-option -g base-index\\; " \ "show-window-option -g pane-base-index\\;" end
Source
# File lib/tmuxinator/project.rb, line 225 def socket if socket_path " -S #{socket_path}" elsif socket_name " -L #{socket_name}" end end
Source
# File lib/tmuxinator/project.rb, line 233 def socket_name yaml["socket_name"] end
Source
# File lib/tmuxinator/project.rb, line 237 def socket_path yaml["socket_path"] end
Source
# File lib/tmuxinator/project.rb, line 269 def startup_pane pane = if blank?(yaml["startup_pane"]) pane_base_index else yaml["startup_pane"] end "#{startup_window}.#{pane}" end
Source
# File lib/tmuxinator/project.rb, line 265 def startup_window "#{name}:#{yaml['startup_window'] || base_index}" end
Source
# File lib/tmuxinator/project.rb, line 195 def tmux "#{tmux_command}#{tmux_options}#{socket}" end
Source
# File lib/tmuxinator/project.rb, line 199 def tmux_command yaml["tmux_command"] || "tmux" end
Source
# File lib/tmuxinator/project.rb, line 207 def tmux_has_session?(name) return false unless 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
Source
# File lib/tmuxinator/project.rb, line 391 def tmux_kill_session_command "#{tmux} kill-session -t #{name}" end
Source
# File lib/tmuxinator/project.rb, line 384 def tmux_new_session_command return if append? window = windows.first.tmux_window_name_option "#{tmux} new-session -d -s #{name} #{window}" end
Source
# File lib/tmuxinator/project.rb, line 241 def tmux_options if cli_args? " #{yaml['cli_args'].to_s.strip}" elsif tmux_options? " #{yaml['tmux_options'].to_s.strip}" else "" end end
Source
# File lib/tmuxinator/project.rb, line 280 def tmux_options? yaml["tmux_options"] end
Source
# File lib/tmuxinator/project.rb, line 408 def tmux_set_pane_title_format(tmux_window_target) command = set_window_option(tmux_window_target) if pane_title_format? "#{command} pane-border-format \"#{yaml['pane_title_format']}\"" else "#{command} pane-border-format \"\#{pane_index}: \#{pane_title}\"" end end
Source
# File lib/tmuxinator/project.rb, line 399 def tmux_set_pane_title_position(tmux_window_target) command = set_window_option(tmux_window_target) if pane_title_position? && pane_title_position_valid? "#{command} pane-border-status #{yaml['pane_title_position']}" else "#{command} pane-border-status top" end end
Source
# File lib/tmuxinator/project.rb, line 203 def tmux_startup_pane_command "#{tmux} select-pane -t #{startup_pane}" end
Source
# File lib/tmuxinator/project.rb, line 84 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
Source
# File lib/tmuxinator/project.rb, line 114 def validate_options if @force_attach && @force_detach raise "Cannot force_attach and force_detach at the same time" end if append? && !tmux_has_session?(name) raise "Cannot append to a session that does not exist" end end
Source
# File lib/tmuxinator/project.rb, line 296 def window(index) append? ? ":#{index}" : "#{name}:#{index}" end
Source
# File lib/tmuxinator/project.rb, line 137 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
Private Instance Methods
Source
# File lib/tmuxinator/project.rb, line 434 def blank?(object) (object.respond_to?(:empty?) && object.empty?) || !object end
Source
# File lib/tmuxinator/project.rb, line 442 def extract_tmux_config options_hash = {} `#{show_tmux_options}`. encode("UTF-8", invalid: :replace). split("\n"). map do |entry| key, value = entry.split("\s") options_hash[key] = value options_hash end options_hash end
Source
# File lib/tmuxinator/project.rb, line 457 def legacy_synchronize? (synchronize_options & [true, "before"]).any? end
Source
# File lib/tmuxinator/project.rb, line 487 def pane_title_format? yaml["pane_title_format"] end
Source
# File lib/tmuxinator/project.rb, line 479 def pane_title_position? yaml["pane_title_position"] end
Source
# File lib/tmuxinator/project.rb, line 483 def pane_title_position_valid? ["top", "bottom", "off"].include? yaml["pane_title_position"] end
Source
# File lib/tmuxinator/project.rb, line 471 def parsed_parameters(parameters) parameters.is_a?(Array) ? parameters.join("; ") : parameters end
Source
# File lib/tmuxinator/project.rb, line 491 def print_warning(message) yellow = '\033[1;33m' no_color = '\033[0m' msg = "WARNING: #{message}\n" "printf \"#{yellow}#{msg}#{no_color}\"" end
Source
# File lib/tmuxinator/project.rb, line 498 def set_window_option(tmux_window_target) "#{tmux} set-window-option -t #{tmux_window_target}" end
Source
# File lib/tmuxinator/project.rb, line 461 def synchronize_options window_options.map do |option| option["synchronize"] if option.is_a?(Hash) end end
Source
# File lib/tmuxinator/project.rb, line 438 def tmux_config @tmux_config ||= extract_tmux_config end
Source
# File lib/tmuxinator/project.rb, line 475 def wemux? yaml["tmux_command"] == "wemux" end
Source
# File lib/tmuxinator/project.rb, line 467 def window_options yaml["windows"].map(&:values).flatten end