Class: TmuxConnector::TmuxSession

Inherits:
Object
  • Object
show all
Defined in:
lib/tmux-connector/tmux_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commandsObject

Returns the value of attribute commands.



17
18
19
# File 'lib/tmux-connector/tmux_handler.rb', line 17

def commands
  @commands
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/tmux-connector/tmux_handler.rb', line 15

def name
  @name
end

#sessionObject (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_sessionObject



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