Class: 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.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#panes ⇒ Object
readonly
Returns the value of attribute panes.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #build_commands(_prefix, command_yml) ⇒ Object
- #build_panes(panes_yml) ⇒ Object
-
#initialize(window_yaml, index, project) ⇒ Window
constructor
A new instance of Window.
- #panes? ⇒ Boolean
- #pre ⇒ Object
- #root? ⇒ Boolean
- #tmux_layout_command ⇒ Object
- #tmux_new_window_command ⇒ Object
- #tmux_pre_window_command ⇒ Object
- #tmux_select_first_pane ⇒ Object
- #tmux_tiled_layout_command ⇒ Object
- #tmux_window_command_prefix ⇒ Object
- #tmux_window_name_option ⇒ Object
- #tmux_window_target ⇒ 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 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tmuxinator/window.rb', line 7 def initialize(window_yaml, index, project) @name = if !window_yaml.keys.first.nil? window_yaml.keys.first.to_s.shellescape end @root = nil @panes = [] @layout = nil @pre = nil @project = project @index = index value = window_yaml.values.first if value.is_a?(Hash) @layout = value["layout"] ? value["layout"].shellescape : nil @pre = value["pre"] if value["pre"] @root = if value["root"] File.(value["root"]).shellescape elsif project.root? project.root end @panes = build_panes(value["panes"]) else @commands = build_commands(tmux_window_command_prefix, value) end 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 |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
5 6 7 |
# File 'lib/tmuxinator/window.rb', line 5 def layout @layout end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/tmuxinator/window.rb', line 5 def name @name end |
#panes ⇒ Object (readonly)
Returns the value of attribute panes.
5 6 7 |
# File 'lib/tmuxinator/window.rb', line 5 def panes @panes 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
#build_commands(_prefix, command_yml) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tmuxinator/window.rb', line 47 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
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tmuxinator/window.rb', line 35 def build_panes(panes_yml) Array(panes_yml).map.with_index do |pane_yml, index| if pane_yml.is_a?(Hash) pane_yml.map do |_name, commands| Tmuxinator::Pane.new(index, project, self, *commands) end else Tmuxinator::Pane.new(index, project, self, pane_yml) end end.flatten end |
#panes? ⇒ Boolean
71 72 73 |
# File 'lib/tmuxinator/window.rb', line 71 def panes? panes.any? end |
#pre ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/tmuxinator/window.rb', line 59 def pre if @pre.is_a?(Array) @pre.join(" && ") elsif @pre.is_a?(String) @pre end end |
#tmux_layout_command ⇒ Object
102 103 104 |
# File 'lib/tmuxinator/window.rb', line 102 def tmux_layout_command "#{project.tmux} select-layout -t #{tmux_window_target} #{layout}" end |
#tmux_new_window_command ⇒ Object
93 94 95 96 |
# File 'lib/tmuxinator/window.rb', line 93 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
79 80 81 82 83 |
# File 'lib/tmuxinator/window.rb', line 79 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
106 107 108 |
# File 'lib/tmuxinator/window.rb', line 106 def tmux_select_first_pane "#{project.tmux} select-pane -t #{tmux_window_target}.#{panes.first.index + project.base_index}" end |
#tmux_tiled_layout_command ⇒ Object
98 99 100 |
# File 'lib/tmuxinator/window.rb', line 98 def tmux_tiled_layout_command "#{project.tmux} select-layout -t #{tmux_window_target} tiled" end |
#tmux_window_command_prefix ⇒ Object
85 86 87 |
# File 'lib/tmuxinator/window.rb', line 85 def tmux_window_command_prefix "#{project.tmux} send-keys -t #{project.name}:#{index + project.base_index}" end |
#tmux_window_name_option ⇒ Object
89 90 91 |
# File 'lib/tmuxinator/window.rb', line 89 def tmux_window_name_option name ? "-n #{name}" : "" end |
#tmux_window_target ⇒ Object
75 76 77 |
# File 'lib/tmuxinator/window.rb', line 75 def tmux_window_target "#{project.name}:#{index + project.base_index}" end |