Class: I2Cssh

Inherits:
Object
  • Object
show all
Defined in:
lib/i2cssh.rb

Instance Method Summary collapse

Constructor Details

#initialize(servers, ssh_options, i2_options, ssh_environment) ⇒ I2Cssh

Returns a new instance of I2Cssh.



3
4
5
6
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
34
35
36
37
38
39
40
# File 'lib/i2cssh.rb', line 3

def initialize servers, ssh_options, i2_options, ssh_environment
    @ssh_prefix         = "ssh " + ssh_options.join(' ')
    @ssh_options        = ssh_options
    @i2_options         = i2_options.clone
    @servers            = servers
    @ssh_environment    = ssh_environment

    raise Exception.new 'No servers given' if servers.empty?

    @sys_events = Appscript.app.by_name('System Events')
    @iterm = Appscript.app.by_name("iTerm")

    @pane_menu = @sys_events.processes["iTerm2"].menu_bars[1].menu_bar_items["Window"].menus["Window"].menu_items["Select Split Pane"].menus["Select Split Pane"]
    @shell_menu = @sys_events.processes["iTerm2"].menu_bars[1].menu_bar_items["Shell"].menus["Shell"]

    @profile = i2_options.first[:profile] || "Default"
    @shell = "/usr/bin/env bash"

    @iterm.create_window_with_profile(@profile, :command => "#{@shell} -l")
    @window = @iterm.current_window

    while !@servers.empty? do
        compute_geometry
        split_session
        start_ssh
        enable_broadcast if i2_options.first[:broadcast]
        @servers.shift
        @i2_options.shift
        @ssh_environment.shift

        if !@servers.empty?  && i2_options.first[:tabs] then
            # @iterm.create_tab(@profile)
            @window.create_tab_with_default_profile()
            @session_index = 0
        end
    end
    @window.select(@window.tabs[1])
end