Class: TmuxConnector::TmuxSession
- Inherits:
-
Object
- Object
- TmuxConnector::TmuxSession
- Defined in:
- lib/tmux-connector/tmux_handler.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#initialize(session) ⇒ TmuxSession
constructor
A new instance of TmuxSession.
- #send_commands(send_commands, server_regex, group_regex, window, verbose) ⇒ Object
- #start_session ⇒ Object
Constructor Details
#initialize(session) ⇒ TmuxSession
Returns a new instance of TmuxSession.
19 20 21 22 23 24 |
# File 'lib/tmux-connector/tmux_handler.rb', line 19 def initialize(session) @session = session @name = session.name @commands = [] end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
17 18 19 |
# File 'lib/tmux-connector/tmux_handler.rb', line 17 def commands @commands end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/tmux-connector/tmux_handler.rb', line 15 def name @name end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
16 17 18 |
# File 'lib/tmux-connector/tmux_handler.rb', line 16 def session @session end |
Instance Method Details
#send_commands(send_commands, server_regex, group_regex, window, verbose) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tmux-connector/tmux_handler.rb', line 39 def send_commands(send_commands, server_regex, group_regex, window, verbose) count = 0 each_pane do |window_index, pane_index, pane| if window matches = window == window_index.to_s else matches = server_regex.nil? && group_regex.nil? matches ||= !server_regex.nil? && pane.host.ssh_name.match(server_regex) matches ||= !group_regex.nil? && session.merge_rules[pane.host.group_id].match(group_regex) end if matches system("tmux send-keys -t #{ name }:#{ window_index }.#{ pane_index } '#{ send_commands }' C-m") count += 1 end end puts "command sent to #{ count } server[s]" if verbose end |
#start_session ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tmux-connector/tmux_handler.rb', line 26 def start_session() create_session create_windows create_panes clear_panes connect attach_to_session execute end |