Class: Tmuxinator::Window
- Inherits:
-
Object
- Object
- Tmuxinator::Window
- Includes:
- Util
- Defined in:
- lib/tmuxinator/window.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #_hashed? ⇒ Boolean
- #_project_root ⇒ Object
- #_yaml_root ⇒ Object
- #build_commands(_prefix, command_yml) ⇒ Object
- #build_panes(panes_yml) ⇒ Object
-
#initialize(window_yaml, index, project) ⇒ Window
constructor
A new instance of Window.
- #layout ⇒ Object
- #panes ⇒ Object
- #panes? ⇒ Boolean
- #pre ⇒ Object
- #root ⇒ Object
- #root? ⇒ Boolean
- #synchronize ⇒ Object
- #synchronize_after? ⇒ Boolean
- #synchronize_before? ⇒ Boolean
- #tmux_layout_command ⇒ Object
- #tmux_new_window_command ⇒ Object
- #tmux_pre_window_command ⇒ Object
- #tmux_select_first_pane ⇒ Object
- #tmux_synchronize_panes ⇒ Object
- #tmux_tiled_layout_command ⇒ Object
- #tmux_window_command_prefix ⇒ Object
- #tmux_window_name_option ⇒ Object
- #tmux_window_target ⇒ Object
- #yaml ⇒ Object
Methods included from Util
Constructor Details
#initialize(window_yaml, index, project) ⇒ Window
Returns a new instance of Window.
7 8 9 10 11 12 13 14 15 |
# File 'lib/tmuxinator/window.rb', line 7 def initialize(window_yaml, index, project) first_key = window_yaml.keys.first @name = first_key.to_s.shellescape unless first_key.nil? @yaml = window_yaml.values.first @project = project @index = index @commands = build_commands(tmux_window_command_prefix, @yaml) end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
5 6 7 |
# File 'lib/tmuxinator/window.rb', line 5 def commands @commands end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
5 6 7 |
# File 'lib/tmuxinator/window.rb', line 5 def index @index end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/tmuxinator/window.rb', line 5 def name @name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
5 6 7 |
# File 'lib/tmuxinator/window.rb', line 5 def project @project end |
Instance Method Details
#_hashed? ⇒ Boolean
21 22 23 |
# File 'lib/tmuxinator/window.rb', line 21 def _hashed? @yaml.is_a?(Hash) end |
#_project_root ⇒ Object
45 46 47 |
# File 'lib/tmuxinator/window.rb', line 45 def _project_root project.root if project.root? end |
#_yaml_root ⇒ Object
41 42 43 |
# File 'lib/tmuxinator/window.rb', line 41 def _yaml_root File.(yaml["root"]).shellescape if yaml["root"] end |
#build_commands(_prefix, command_yml) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tmuxinator/window.rb', line 66 def build_commands(_prefix, command_yml) if command_yml.is_a?(Array) command_yml.map do |command| "#{tmux_window_command_prefix} #{command.shellescape} C-m" if command end.compact elsif command_yml.is_a?(String) && !command_yml.empty? ["#{tmux_window_command_prefix} #{command_yml.shellescape} C-m"] else [] end end |
#build_panes(panes_yml) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/tmuxinator/window.rb', line 49 def build_panes(panes_yml) return if panes_yml.nil? Array(panes_yml).map.with_index do |pane_yml, index| commands = case pane_yml when Hash pane_yml.values.first when Array pane_yml else pane_yml end Tmuxinator::Pane.new(index, project, self, *commands) end.flatten end |
#layout ⇒ Object
29 30 31 |
# File 'lib/tmuxinator/window.rb', line 29 def layout yaml["layout"] ? yaml["layout"].shellescape : nil end |
#panes ⇒ Object
17 18 19 |
# File 'lib/tmuxinator/window.rb', line 17 def panes build_panes(yaml["panes"]) || [] end |
#panes? ⇒ Boolean
92 93 94 |
# File 'lib/tmuxinator/window.rb', line 92 def panes? panes.any? end |
#pre ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/tmuxinator/window.rb', line 78 def pre _pre = yaml["pre"] if _pre.is_a?(Array) _pre.join(" && ") elsif _pre.is_a?(String) _pre end end |
#root ⇒ Object
37 38 39 |
# File 'lib/tmuxinator/window.rb', line 37 def root _yaml_root || _project_root end |
#synchronize ⇒ Object
33 34 35 |
# File 'lib/tmuxinator/window.rb', line 33 def synchronize yaml["synchronize"] || false end |
#synchronize_after? ⇒ Boolean
139 140 141 |
# File 'lib/tmuxinator/window.rb', line 139 def synchronize_after? synchronize == "after" end |
#synchronize_before? ⇒ Boolean
135 136 137 |
# File 'lib/tmuxinator/window.rb', line 135 def synchronize_before? synchronize == true || synchronize == "before" end |
#tmux_layout_command ⇒ Object
127 128 129 |
# File 'lib/tmuxinator/window.rb', line 127 def tmux_layout_command "#{project.tmux} select-layout -t #{tmux_window_target} #{layout}" end |
#tmux_new_window_command ⇒ Object
114 115 116 117 |
# File 'lib/tmuxinator/window.rb', line 114 def tmux_new_window_command path = root? ? "#{Tmuxinator::Config.default_path_option} #{root}" : nil "#{project.tmux} new-window #{path} -t #{tmux_window_target} #{tmux_window_name_option}" end |
#tmux_pre_window_command ⇒ Object
100 101 102 103 104 |
# File 'lib/tmuxinator/window.rb', line 100 def tmux_pre_window_command return unless project.pre_window "#{project.tmux} send-keys -t #{tmux_window_target} #{project.pre_window.shellescape} C-m" end |
#tmux_select_first_pane ⇒ Object
131 132 133 |
# File 'lib/tmuxinator/window.rb', line 131 def tmux_select_first_pane "#{project.tmux} select-pane -t #{tmux_window_target}.#{panes.first.index + project.pane_base_index}" end |
#tmux_synchronize_panes ⇒ Object
123 124 125 |
# File 'lib/tmuxinator/window.rb', line 123 def tmux_synchronize_panes "#{project.tmux} set-window-option -t #{tmux_window_target} synchronize-panes on" end |
#tmux_tiled_layout_command ⇒ Object
119 120 121 |
# File 'lib/tmuxinator/window.rb', line 119 def tmux_tiled_layout_command "#{project.tmux} select-layout -t #{tmux_window_target} tiled" end |
#tmux_window_command_prefix ⇒ Object
106 107 108 |
# File 'lib/tmuxinator/window.rb', line 106 def tmux_window_command_prefix "#{project.tmux} send-keys -t #{project.name}:#{index + project.base_index}" end |
#tmux_window_name_option ⇒ Object
110 111 112 |
# File 'lib/tmuxinator/window.rb', line 110 def tmux_window_name_option name ? "-n #{name}" : "" end |
#tmux_window_target ⇒ Object
96 97 98 |
# File 'lib/tmuxinator/window.rb', line 96 def tmux_window_target "#{project.name}:#{index + project.base_index}" end |
#yaml ⇒ Object
25 26 27 |
# File 'lib/tmuxinator/window.rb', line 25 def yaml _hashed? ? @yaml : {} end |