Class: Tmuxinator::Window
- Inherits:
-
Object
- Object
- Tmuxinator::Window
show all
- Includes:
- Util
- Defined in:
- lib/tmuxinator/window.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util
#current_session_name, #exit!, #yes_no
Constructor Details
#initialize(window_yaml, index, project) ⇒ Window
Returns a new instance of Window.
9
10
11
12
13
14
15
16
17
|
# File 'lib/tmuxinator/window.rb', line 9
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
Returns the value of attribute commands.
7
8
9
|
# File 'lib/tmuxinator/window.rb', line 7
def commands
@commands
end
|
#index ⇒ Object
Returns the value of attribute index.
7
8
9
|
# File 'lib/tmuxinator/window.rb', line 7
def index
@index
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/tmuxinator/window.rb', line 7
def name
@name
end
|
#project ⇒ Object
Returns the value of attribute project.
7
8
9
|
# File 'lib/tmuxinator/window.rb', line 7
def project
@project
end
|
Instance Method Details
#_hashed? ⇒ Boolean
23
24
25
|
# File 'lib/tmuxinator/window.rb', line 23
def _hashed?
@yaml.is_a?(Hash)
end
|
#_project_root ⇒ Object
51
52
53
|
# File 'lib/tmuxinator/window.rb', line 51
def _project_root
project.root if project.root?
end
|
#_yaml_root ⇒ Object
47
48
49
|
# File 'lib/tmuxinator/window.rb', line 47
def _yaml_root
yaml["root"]
end
|
#build_commands(_prefix, command_yml) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/tmuxinator/window.rb', line 72
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/tmuxinator/window.rb', line 55
def build_panes(panes_yml)
return if panes_yml.nil?
Array(panes_yml).map.with_index do |pane_yml, index|
commands, title = case pane_yml
when Hash
[pane_yml.values.first, pane_yml.keys.first]
when Array
[pane_yml, nil]
else
[pane_yml, nil]
end
Tmuxinator::Pane.new(index, project, self, *commands, title: title)
end.flatten
end
|
#layout ⇒ Object
31
32
33
|
# File 'lib/tmuxinator/window.rb', line 31
def layout
yaml["layout"]&.shellescape
end
|
#panes ⇒ Object
19
20
21
|
# File 'lib/tmuxinator/window.rb', line 19
def panes
build_panes(yaml["panes"]) || []
end
|
#panes? ⇒ Boolean
98
99
100
|
# File 'lib/tmuxinator/window.rb', line 98
def panes?
panes.any?
end
|
#pre ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/tmuxinator/window.rb', line 84
def pre
_pre = yaml["pre"]
if _pre.is_a?(Array)
_pre.join(" && ")
elsif _pre.is_a?(String)
_pre
end
end
|
#root ⇒ Object
The expanded, joined window root path Relative paths are joined to the project root
41
42
43
44
45
|
# File 'lib/tmuxinator/window.rb', line 41
def root
return _project_root unless _yaml_root
File.expand_path(_yaml_root, _project_root).shellescape
end
|
#root? ⇒ Boolean
94
95
96
|
# File 'lib/tmuxinator/window.rb', line 94
def root?
!root.nil?
end
|
#synchronize ⇒ Object
35
36
37
|
# File 'lib/tmuxinator/window.rb', line 35
def synchronize
yaml["synchronize"] || false
end
|
#synchronize_after? ⇒ Boolean
145
146
147
|
# File 'lib/tmuxinator/window.rb', line 145
def synchronize_after?
synchronize == "after"
end
|
#synchronize_before? ⇒ Boolean
141
142
143
|
# File 'lib/tmuxinator/window.rb', line 141
def synchronize_before?
[true, "before"].include?(synchronize)
end
|
#tmux_layout_command ⇒ Object
133
134
135
|
# File 'lib/tmuxinator/window.rb', line 133
def tmux_layout_command
"#{project.tmux} select-layout -t #{tmux_window_target} #{layout}"
end
|
#tmux_new_window_command ⇒ Object
120
121
122
123
|
# File 'lib/tmuxinator/window.rb', line 120
def tmux_new_window_command
path = root? ? "#{Tmuxinator::Config.default_path_option} #{root}" : nil
"#{project.tmux} new-window #{path} -k -t #{tmux_window_target} #{tmux_window_name_option}"
end
|
#tmux_pre_window_command ⇒ Object
106
107
108
109
110
|
# File 'lib/tmuxinator/window.rb', line 106
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
137
138
139
|
# File 'lib/tmuxinator/window.rb', line 137
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
129
130
131
|
# File 'lib/tmuxinator/window.rb', line 129
def tmux_synchronize_panes
"#{project.tmux} set-window-option -t #{tmux_window_target} synchronize-panes on"
end
|
#tmux_tiled_layout_command ⇒ Object
125
126
127
|
# File 'lib/tmuxinator/window.rb', line 125
def tmux_tiled_layout_command
"#{project.tmux} select-layout -t #{tmux_window_target} tiled"
end
|
#tmux_window_command_prefix ⇒ Object
112
113
114
|
# File 'lib/tmuxinator/window.rb', line 112
def tmux_window_command_prefix
"#{project.tmux} send-keys -t #{project.name}:#{index + project.base_index}"
end
|
#tmux_window_name_option ⇒ Object
116
117
118
|
# File 'lib/tmuxinator/window.rb', line 116
def tmux_window_name_option
name ? "-n #{name}" : ""
end
|
#tmux_window_target ⇒ Object
102
103
104
|
# File 'lib/tmuxinator/window.rb', line 102
def tmux_window_target
"#{project.name}:#{index + project.base_index}"
end
|
#yaml ⇒ Object
27
28
29
|
# File 'lib/tmuxinator/window.rb', line 27
def yaml
_hashed? ? @yaml : {}
end
|