i2c2 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01bf03ba44e3c2eb7eb06a573d0c92d09519850ddccbdca376f8ba034b6aca2d
4
+ data.tar.gz: ac6c004c03542c1ef81d38be6646a4fa5514d8743ef4317ba16cc1d8f53483cc
5
+ SHA512:
6
+ metadata.gz: ac3bb801c2213fd33273e7152743ad40d46f8db4d6b75f88663191c56f077380c53a982032581cfbea1a4f89a6c59098fbbf9007e6e7aabe57c59dde1af4d83e
7
+ data.tar.gz: cc5adb3e867601ba620a66f8f787bbdb7a084d344c5637c15d51a253b2812c26f67d9fe54901ad8734146b2ed3af2507e649a97296e636167429354649569b78
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", ">= 1.0.0"
10
+ gem "jeweler", "2.1.2"
11
+ gem "shoulda"
12
+ gem "builder"
13
+ end
14
+
@@ -0,0 +1,63 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.6.0)
5
+ public_suffix (>= 2.0.2, < 4.0)
6
+ builder (3.2.2)
7
+ descendants_tracker (0.0.4)
8
+ thread_safe (~> 0.3, >= 0.3.1)
9
+ faraday (0.9.2)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.5.0)
12
+ github_api (0.11.3)
13
+ addressable (~> 2.3)
14
+ descendants_tracker (~> 0.0.1)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 1.2)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ nokogiri (~> 1.6.0)
19
+ oauth2
20
+ hashie (3.6.0)
21
+ highline (2.0.2)
22
+ jeweler (2.1.2)
23
+ builder
24
+ bundler (>= 1.0)
25
+ git (>= 1.2.5)
26
+ github_api (~> 0.11.0)
27
+ highline (>= 1.6.15)
28
+ nokogiri (>= 1.5.10)
29
+ rake
30
+ rdoc
31
+ semver
32
+ jwt (1.5.6)
33
+ mini_portile2 (2.1.0)
34
+ multi_json (1.13.1)
35
+ multi_xml (0.6.0)
36
+ multipart-post (2.1.0)
37
+ nokogiri (1.6.8.1)
38
+ mini_portile2 (~> 2.1.0)
39
+ oauth2 (1.4.1)
40
+ faraday (>= 0.8, < 0.16.0)
41
+ jwt (>= 1.0, < 3.0)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (>= 1.2, < 3)
45
+ public_suffix (2.0.5)
46
+ rack (1.6.11)
47
+ rake (12.3.2)
48
+ rdoc (5.1.0)
49
+ semver (1.0.1)
50
+ shoulda (2.11.3)
51
+ thread_safe (0.3.6)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ builder
58
+ bundler (>= 1.0.0)
59
+ jeweler (= 2.1.2)
60
+ shoulda
61
+
62
+ BUNDLED WITH
63
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2019 dx7
2
+ Copyright (c) 2011-2018 Wouter de Bie
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,220 @@
1
+ # i2c2
2
+
3
+ i2c2 is a csshX (http://code.google.com/p/csshx/) like tool for connecting over ssh to multiple machines. But instead of creating separate windows and having
4
+ a master window for input, i2c2 uses iterm2 split panes and "Send input to all sessions" (cmd-shift-i) to send commands to all sessions.
5
+
6
+ i2c2 is based on i2cssh which was a great project created by Wouter de Bie but unfortunately i2cssh had its latest release on July 15, 2016, almost 3 years ago.
7
+ i2c2 is here just to keep i2cssh alive and up to date.
8
+
9
+ ## Installing
10
+
11
+ When using iTerm2 < 2.9, install old i2cssh version 1.16.0:
12
+
13
+ $ gem install i2cssh -v 1.16.0
14
+
15
+ Otherwise, just run:
16
+
17
+ $ gem install i2c2
18
+
19
+ ## Migrate from i2cssh
20
+
21
+ If you have used i2cssh and want to migrate, you can do it painless using i2c2 version 0.99.0 which is 100% compatible with i2cssh 2.2.0 (latest version),
22
+ including the config file ~/.i2csshrc.
23
+
24
+ ## Usage
25
+ Usage: i2c2 [options] [(username@host [username@host] | username@cluster)]
26
+ -c, --clusters clus1,clus2 Comma-separated list of clusters specified in ~/.i2csshrc
27
+ -m, --machines a,b,c Comma-separated list of hosts
28
+ -f, --file FILE Cluster file (one hostname per line)
29
+ -t, --tab-split Split servers/clusters into tabs (group arguments)
30
+ -T, --tab-split-nogroup Split servers/clusters into tabs (don't group arguments)
31
+ -A, --forward-agent Enable SSH agent forwarding
32
+ -l, --login LOGIN SSH login name
33
+ -e, --environment KEY=VAL Send environment vars (comma-separated list, need to start with LC_)
34
+ -r, --rank Send LC_RANK with the host number as environment variable
35
+ -F, --fullscreen Make the window fullscreen
36
+ -C, --columns COLUMNS Number of columns (rows will be calculated)
37
+ -R, --rows ROWS Number of rows (columns will be calculated)
38
+ -b, --broadcast Start with broadcast input (DANGEROUS!)
39
+ -nb, --nobroadcast Disable broadcast
40
+ -p, --profile PROFILE Name of the iTerm2 profile (default: Default)
41
+ -2, --iterm2 Use iTerm2 instead of iTerm
42
+ -i, --itermname NAME Name of the application to use (default: iTerm)
43
+ -s, --sleep SLEEP Number of seconds to sleep between creating SSH sessions
44
+ -d, --direction DIRECTION Direction that new sessions are created (default: column)
45
+ -X, --extra EXTRA_PARAM Additional ssh parameters (e.g. -Xi=myidentity.pem)
46
+
47
+ i2c2 will assume you want to connect to a cluster when only one host is given.
48
+
49
+ For `-c` and `-m` options, the format `username@cluster` or `username@host` can be used.
50
+
51
+ The following commands are exactly the same, however, they might serve different purposes:
52
+
53
+ $ i2c2 -m user1@host1,user2@host2
54
+ $ i2c2 user1@host1 user2@host2
55
+
56
+ You can combine these options and use them multiple times:
57
+
58
+ $ i2c2 -m user1@host1,user2@host2 -m user3@host3 user4@host4 user5@host5
59
+
60
+ Using the `-l` option will override all usernames:
61
+
62
+ $ i2c2 -l foo user1@host1 user2@host2
63
+
64
+ This will connect to both `host1` and `host2` as the user `foo`
65
+
66
+ ## i2csshrc
67
+
68
+ The `i2csshrc` file is a YAML formatted file that contains the following structure:
69
+
70
+ ---
71
+ version: 2
72
+ [optional parameters]
73
+ clusters:
74
+ mycluster:
75
+ [optional parameters]
76
+ hosts:
77
+ - host1
78
+ - host2
79
+
80
+ Optional parameters can be used globally or per cluster and include:
81
+
82
+ broadcast: (true/false) # Enable/disable broadcast on start
83
+ login: <username> # Use this username for login
84
+ profile: <iTerm2 profile> # Use this iTerm profile
85
+ rank: (true/false) # Enable sending LC_RANK as an environment variable
86
+ columns: <cols> # Amount of columns
87
+ rows: <rows> # Amount of rows
88
+ sleep: <secs> # Seconds to sleep between creating SSH sessions
89
+ direction: (column/row) # Direction that new sessions are created (default: column)
90
+ itermname: # iTerm app name (default: iTerm)
91
+
92
+ environment: # Send the following enviroment variables
93
+ - LC_FOO: foo
94
+ - LC_BAR: bar
95
+
96
+ iterm2: true # Use iTerm2.app instead of iTerm.app (only available globally)
97
+
98
+ Note: rows and columns can't be used together.
99
+
100
+ The following precedence is used:
101
+
102
+ `global options from config` < `cluster options from config` < `command line flags`
103
+
104
+ Make sure the config file is valid YAML (e.g. use spaces instead of tabs)
105
+
106
+ ## Options
107
+
108
+ ### -A, --forward-agent
109
+
110
+ Enable SSH agent forwarding
111
+
112
+ ### -l, --login LOGIN
113
+
114
+ This option will override all logins passed in to i2c2. This goes for global config, cluster config or username@host passed on the command line
115
+
116
+ ### -e, --environment KEY=VAL
117
+
118
+ Allows for passing environment varables to the SSH session. This can be a comma-separated list: `-e LC_FOO=foo,LC_BAR=bar`
119
+
120
+ ### -F, --fullscreen
121
+
122
+ Enable fullscreen on startup
123
+
124
+ ### -C, --columns COLUMNS
125
+
126
+ Set the amount of columns. Can't be used in conjunction with -R
127
+
128
+ ### -R, --rows ROWS
129
+
130
+ Set the amount of columns. Can't be used in conjunction with -C
131
+
132
+ ### -b, --broadcast
133
+
134
+ Enable broadcast on startup. i2c2 will send cmd-shift-i to the window and press the OK button.
135
+
136
+ ### -nb, --nobroadcast
137
+
138
+ Disable broadcast. This setting can be used to disable any broadcast that was set in the config.
139
+
140
+ ### -p, --profile PROFILE
141
+
142
+ Use a specific iTerm profile
143
+
144
+ ### -2, --iterm2
145
+
146
+ Use iTerm2.app instead of iTerm.app
147
+
148
+ ### -i, --itermname NAME
149
+
150
+ Name of the application to use (default: iTerm). It happens sometimes iTerm isn't called iTerm. Use this parameter to override what app i2c2 interacts with.
151
+
152
+ ### -f, --file
153
+
154
+ Will read nodes from a file. These will be added to any hosts specified on the command line or in the config
155
+
156
+ ### -c, --clusters clus1,clus2
157
+
158
+ Connect to one or more clusters that are specified in the config
159
+
160
+ ### -r, --rank
161
+
162
+ Send a LC_RANK environment variable different for each host (from 0 to n)
163
+
164
+ ### -m, --machines a,b,c
165
+
166
+ Connect to the machines a, b and c
167
+
168
+ ### -t, --tab-split
169
+
170
+ Split servers/clusters into tabs, grouping arguments.
171
+ Tabs are created as follows: hosts after a -m option are put in one tab, each cluster is always in its own tab, all the arguments are in one tab.
172
+
173
+ ### -T, --tab-split-nogroup
174
+
175
+ Split servers/clusters into tabs, *not* grouping arguments.
176
+ Tabs are created as follows: hosts after a -m option are put in one tab, each cluster is always in its own tab, each argument is in its own tab.
177
+
178
+ ### -s, --sleep SLEEP
179
+
180
+ Wait SLEEP seconds between starting each ssh session. This will take decimals as well (0.5 for half a second)
181
+
182
+ ### -X, --extra EXTRA
183
+
184
+ Set extra ssh parameters in the form -Xk=v. For example:
185
+
186
+ i2c2 -Xi=myidentity.pem
187
+
188
+ will result in
189
+
190
+ ssh -i myidentity.pem
191
+
192
+ Or,
193
+
194
+ i2c2 -Xp=2222 -XL=8080:localhost:8080
195
+
196
+ will result in
197
+
198
+ ssh -p 2222 -L 8080:localhost:8080
199
+
200
+ ## TODO
201
+
202
+ - Functional parity with csshX (as far as possible)
203
+ - -X support in config file
204
+
205
+ ## Contributing to i2c2
206
+
207
+ I know that i2c2 doesn't have all the functionality of csshX, but either let me know what you really need or
208
+ fork, hack and create a pull request.
209
+
210
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
211
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
212
+ * Fork the project
213
+ * Start a feature/bugfix branch
214
+ * Commit and push until you are happy with your contribution
215
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
216
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
217
+
218
+ ## Copyright
219
+
220
+ See LICENSE.txt for further details.
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "i2c2"
18
+ gem.homepage = "http://github.com/dx7/i2c2"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{csshX like cluster ssh using iTerm2 panes}
21
+ gem.description = %Q{csshX like cluster ssh using iTerm2 panes}
22
+ gem.email = "dx7@pm.me"
23
+ gem.authors = ["dx7", "Wouter de Bie"]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency 'rb-scpt', "~> 1.0.1"
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "i2c2 #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.99.0
@@ -0,0 +1,298 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'optparse'
4
+ require_relative '../lib/i2c2'
5
+ require 'yaml'
6
+
7
+ @config_file = File.expand_path "~/.i2csshrc"
8
+
9
+ @i2_options, ssh_options, @servers, @clusters, @ssh_environment, opts_from_cmdline = [], [], [], {}, [], {}
10
+
11
+ def get_hosts(c)
12
+ c.each do |clus|
13
+
14
+ if clus =~ /(.+)@(.+)/
15
+ login_from_cli = $1
16
+ clus = $2
17
+ end
18
+
19
+ cluster = @clusters[clus]
20
+ if cluster
21
+ set_options(cluster, login_from_cli)
22
+
23
+ if @i2_options.last[:login]
24
+ @servers << cluster["hosts"].map{|h| "#{@i2_options.last[:login]}@#{h}"}
25
+ else
26
+ @servers << cluster["hosts"]
27
+ end
28
+ else
29
+ puts "ERROR: unknown cluster #{c}. Check your #{@config_file}"
30
+ exit 1
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ def set_options(config_hash, login_override=nil)
37
+ if config_hash["columns"] and config_hash["rows"]
38
+ puts "CONFIG ERROR: rows and columns can't be used at the same time"
39
+ exit 1
40
+ end
41
+
42
+ if @i2_options.size == 0
43
+ @i2_options << {}
44
+ else
45
+ # The first member includes the default options from the conf file
46
+ @i2_options << @i2_options.first.clone
47
+ end
48
+
49
+ [:broadcast, :profile, :rank, :iterm2, :login, :columns, :rows, :sleep, :direction, :itermname].each do |p|
50
+ @i2_options.last[p] = config_hash[p.to_s].nil? ? @i2_options.last[p] : config_hash[p.to_s]
51
+ end
52
+
53
+ @i2_options.last[:login] = login_override if login_override
54
+ @i2_options.last[:direction] ||= :column
55
+ @i2_options.last[:direction] = @i2_options.last[:direction].to_sym
56
+ if config_hash["environment"]
57
+ if @ssh_environment.empty?
58
+ @ssh_environment << {}
59
+ else
60
+ # We have some global env so copy it
61
+ @ssh_environment << @ssh_environment.first.clone
62
+ end
63
+
64
+ @ssh_environment.last.merge!(config_hash["environment"].inject({}){|m, v| m.merge(v)})
65
+ else
66
+ @ssh_environment << {}
67
+ end
68
+
69
+ end
70
+
71
+ if File.exists?(@config_file)
72
+ config_hash = YAML.load File.read @config_file
73
+
74
+ # Read config and set defaults from config
75
+ if config_hash["version"] && config_hash["version"].to_i >= 2
76
+ set_options(config_hash)
77
+ @clusters = config_hash["clusters"]
78
+ else
79
+ # Convert version 1 format to version 2
80
+ @clusters = config_hash["clusters"].inject({}){|m, c| m[c[0]] = {"hosts" => c[1]}; m}
81
+ end
82
+
83
+ else
84
+ set_options({})
85
+ end
86
+
87
+
88
+ optparse = OptionParser.new do |opts|
89
+ opts.banner = "Usage: #{File.basename(__FILE__)} [options] [(username@host [username@host] | username@cluster)]"
90
+
91
+ # Check if we have a cluster.
92
+ opts.on '-c', '--clusters clus1,clus2', Array,
93
+ 'Comma-separated list of clusters specified in ~/.i2csshrc' do |c|
94
+ get_hosts(c)
95
+ end
96
+
97
+
98
+ opts.on '-m', '--machines a,b,c', Array,
99
+ 'Comma-separated list of hosts' do |h|
100
+
101
+ # Add to servers array and get a clone of default options
102
+ @servers << h
103
+ @i2_options << @i2_options.first.clone
104
+ if @ssh_environment.empty?
105
+ @ssh_environment << {}
106
+ else
107
+ @ssh_environment << @ssh_environment.first.clone
108
+ end
109
+ end
110
+
111
+ # Hosts
112
+ opts.on '-f', '--file FILE',
113
+ 'Cluster file (one hostname per line)' do |f|
114
+ @servers << File.read(f).split("\n")
115
+ @i2_options << @i2_options.first.clone
116
+ if @ssh_environment.empty?
117
+ @ssh_environment << {}
118
+ else
119
+ @ssh_environment << @ssh_environment.first.clone
120
+ end
121
+ end
122
+
123
+ opts.on '-t', '--tab-split',
124
+ 'Split servers/clusters into tabs (group arguments)' do
125
+ opts_from_cmdline[:tabs] = true
126
+ end
127
+
128
+ opts.on '-T', '--tab-split-nogroup',
129
+ 'Split servers/clusters into tabs (don\'t group arguments)' do
130
+ opts_from_cmdline[:tabs] = true
131
+ opts_from_cmdline[:tabs_nogroup] = true
132
+ end
133
+
134
+ # Command line options override config file
135
+
136
+ # SSH options
137
+ opts.on '-A', '--forward-agent',
138
+ 'Enable SSH agent forwarding' do
139
+ ssh_options << '-A'
140
+ end
141
+
142
+ opts.on '-l', '--login LOGIN',
143
+ 'SSH login name' do |u|
144
+ opts_from_cmdline[:login] = u
145
+
146
+ end
147
+
148
+ opts.on '-e', '--environment KEY=VAL',
149
+ 'Send environment vars (comma-separated list, need to start with LC_)' do |e|
150
+ #Overwrite global ssh environment from config file
151
+ @ssh_environment[0] = e.split(",").inject({}) {|m, x| key, val = x.split("="); m[key] = val; m}
152
+ end
153
+
154
+ opts.on '-r', '--rank',
155
+ 'Send LC_RANK with the host number as environment variable' do
156
+ opts_from_cmdline[:rank] = true
157
+ end
158
+
159
+ # iTerm2 options
160
+ opts.on '-F', '--fullscreen',
161
+ 'Make the window fullscreen' do
162
+ opts_from_cmdline[:fullscreen] = true
163
+ end
164
+
165
+ opts.on '-C', '--columns COLUMNS', Integer,
166
+ 'Number of columns (rows will be calculated)' do |c|
167
+ if opts_from_cmdline[:rows]
168
+ puts "ERROR: -C and -R can't be used at the same time"
169
+ puts optparse.help
170
+ exit 1
171
+ else
172
+ opts_from_cmdline[:columns] = c
173
+ end
174
+ end
175
+ opts.on '-R', '--rows ROWS', Integer,
176
+ 'Number of rows (columns will be calculated)' do |r|
177
+ if opts_from_cmdline[:columns]
178
+ puts "ERROR: -C and -R can't be used at the same time"
179
+ puts optparse.help
180
+ exit 1
181
+ else
182
+ opts_from_cmdline[:rows] = r
183
+ end
184
+ end
185
+ opts.on '-b', '--broadcast',
186
+ 'Start with broadcast input (DANGEROUS!)' do
187
+ opts_from_cmdline[:broadcast] = true
188
+ end
189
+ opts.on '-nb', '--nobroadcast',
190
+ 'Disable broadcast' do
191
+ opts_from_cmdline[:broadcast] = false
192
+ end
193
+ opts.on '-p', '--profile PROFILE',
194
+ 'Name of the iTerm2 profile (default: Default)' do |p|
195
+ opts_from_cmdline[:profile] = p
196
+ end
197
+ opts.on "-2", '--iterm2',
198
+ 'Use iTerm2 instead of iTerm' do
199
+ opts_from_cmdline[:iterm2] = true
200
+ end
201
+ opts.on "-i", '--itermname NAME', String,
202
+ 'Name of the application to use (default: iTerm)' do |i|
203
+ opts_from_cmdline[:itermname] = i
204
+ end
205
+ opts.on '-s', '--sleep SLEEP', Float,
206
+ 'Number of seconds to sleep between creating SSH sessions' do |s|
207
+ opts_from_cmdline[:sleep] = s
208
+ end
209
+ opts.on "-d", '--direction DIRECTION', String,
210
+ 'Direction that new sessions are created (default: column)' do |d|
211
+ unless ["row", "column"].include?(d)
212
+ puts "ERROR: -d requires 'row' or 'column'"
213
+ puts optparse.help
214
+ exit 1
215
+ end
216
+ opts_from_cmdline[:direction] = d.to_sym
217
+ end
218
+ opts.on '-X', '--extra EXTRA_PARAM', String,
219
+ 'Additional ssh parameters (e.g. -Xi=myidentity.pem)' do |x|
220
+
221
+ ssh_options << "-" + x.split("=").join(" ")
222
+ end
223
+ opts.on '-g', '--gateway HOST', String,
224
+ 'Multihop SSH connection gateway string (e.g. username@gateway) - usually used with -A' do |g|
225
+ # ssh_gateway = g
226
+ opts_from_cmdline[:gateway] = g
227
+ end
228
+ end
229
+ optparse.parse!
230
+
231
+ if opts_from_cmdline[:tabs]
232
+ puts 'Disabling broadcast for tab split mode...'
233
+ opts_from_cmdline[:broadcast] = false
234
+ end
235
+
236
+ # One argument = one cluster
237
+ if ARGV.length == 1
238
+ c = [ARGV[0]]
239
+ get_hosts(c)
240
+
241
+ # Otherwise we have a list of hosts
242
+ elsif ARGV.length > 1
243
+ if opts_from_cmdline[:tabs_nogroup]
244
+ ARGV.each do |serv|
245
+ @servers << [serv]
246
+ @i2_options << @i2_options.first.clone
247
+ if @ssh_environment.empty?
248
+ @ssh_environment << {}
249
+ else
250
+ @ssh_environment << @ssh_environment.first.clone
251
+ end
252
+ end
253
+ else
254
+ @servers << ARGV
255
+ if @i2_options.size > 1 # We added stuff in with cmdline options
256
+ @i2_options << @i2_options.first.clone
257
+ if @ssh_environment.empty?
258
+ @ssh_environment << {}
259
+ else
260
+ @ssh_environment << @ssh_environment.first.clone
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ # Drop default options
267
+ if @i2_options.size > @servers.size
268
+ @i2_options.shift
269
+ end
270
+
271
+ if @ssh_environment.size > @servers.size
272
+ @ssh_environment.shift
273
+ end
274
+
275
+
276
+ @i2_options.each do |opt|
277
+ opt.merge!(opts_from_cmdline)
278
+ end
279
+
280
+ @i2_options.each_with_index do |opt, i|
281
+ if opt[:login]
282
+ @servers[i] = @servers[i].map{|h| "#{opt[:login]}@#{h.gsub(/.+@/,'')}"}
283
+ end
284
+ if opt[:gateway]
285
+ puts opt[:gateway]
286
+ @servers[i] = @servers[i].map{|h| "#{opt[:gateway]} -t ssh #{h}"}
287
+ end
288
+ end
289
+
290
+
291
+ if @servers.empty?
292
+ puts "ERROR: no servers given"
293
+ puts optparse.help
294
+ exit
295
+ end
296
+
297
+
298
+ I2c2.new @servers, ssh_options, @i2_options, @ssh_environment
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "i2c2"
8
+ s.version = "0.99.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["dx7", "Wouter de Bie"]
12
+ s.date = "2016-07-15"
13
+ s.description = "csshX like cluster ssh using iTerm2 panes"
14
+ s.email = "dx7@pm.me"
15
+ s.executables = ["i2c2"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/i2c2",
29
+ "i2c2.gemspec",
30
+ "lib/i2c2.rb",
31
+ "test/helper.rb",
32
+ "test/test_i2c2.rb"
33
+ ]
34
+ s.homepage = "http://github.com/dx7/i2c2"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "2.0.14.1"
38
+ s.summary = "csshX like cluster ssh using iTerm2 panes"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.0"])
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<builder>, [">= 0"])
48
+ s.add_runtime_dependency(%q<rb-scpt>, ["~> 1.0.1"])
49
+ else
50
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
51
+ s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<builder>, [">= 0"])
54
+ s.add_dependency(%q<rb-scpt>, ["~> 1.0.1"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<builder>, [">= 0"])
61
+ s.add_dependency(%q<rb-scpt>, ["~> 1.0.1"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,167 @@
1
+ require 'rb-scpt'
2
+ class I2c2
3
+ def initialize servers, ssh_options, i2_options, ssh_environment
4
+ @ssh_prefix = "ssh " + ssh_options.join(' ')
5
+ @ssh_options = ssh_options
6
+ @i2_options = i2_options.clone
7
+ @servers = servers
8
+ @ssh_environment = ssh_environment
9
+
10
+ raise Exception.new 'No servers given' if servers.empty?
11
+
12
+ @sys_events = Appscript.app.by_name('System Events')
13
+ @iterm = Appscript.app.by_name("iTerm")
14
+
15
+ @pane_menu = @sys_events.processes["iTerm2"].menu_bars[1].menu_bar_items["Window"].menus["Window"].menu_items["Select Split Pane"].menus["Select Split Pane"]
16
+ @shell_menu = @sys_events.processes["iTerm2"].menu_bars[1].menu_bar_items["Shell"].menus["Shell"]
17
+
18
+ @profile = i2_options.first[:profile] || "Default"
19
+ @shell = "/usr/bin/env bash"
20
+
21
+ @iterm.create_window_with_profile(@profile, :command => "#{@shell} -l")
22
+ @window = @iterm.current_window
23
+
24
+ while !@servers.empty? do
25
+ compute_geometry
26
+ split_session
27
+ start_ssh
28
+ enable_broadcast if i2_options.first[:broadcast]
29
+ @servers.shift
30
+ @i2_options.shift
31
+ @ssh_environment.shift
32
+
33
+ if !@servers.empty? && i2_options.first[:tabs] then
34
+ # @iterm.create_tab(@profile)
35
+ @window.create_tab_with_default_profile()
36
+ @session_index = 0
37
+ end
38
+ end
39
+ @window.select(@window.tabs[1])
40
+ end
41
+
42
+ private
43
+ def maximize(app_name)
44
+ begin
45
+ # OSX >= 10.8 has different behavior for full screen. First try out old behavior.
46
+ fullscreen_bounds = Appscript.app.by_name('Finder').desktop.window.bounds
47
+ window = @iterm.windows.get.sort_by{|x| x.id_.get}.last
48
+ window.bounds.set fullscreen_bounds.get
49
+ rescue
50
+ @sys_events.processes[app_name].windows.first.attributes["AXFullScreen"].value.set(true)
51
+ end
52
+ end
53
+
54
+ def compute_geometry
55
+ # Create geometry when combining and ignore rows/columns preference
56
+ if @servers.size > 1 && !@i2_options.first[:tabs]
57
+ count = 0
58
+ @servers.each do |srv|
59
+ count += srv.size
60
+ end
61
+ else
62
+ count = @servers.first.size
63
+ @rows = @i2_options.first[:rows]
64
+ @columns = @i2_options.first[:columns]
65
+ end
66
+
67
+ if @rows then
68
+ @columns = (count / @rows.to_f).ceil
69
+ elsif @columns then
70
+ @rows = (count / @columns.to_f).ceil
71
+ else
72
+ @columns = Math.sqrt(count).ceil
73
+ @rows = (count / @columns.to_f).ceil
74
+ end
75
+ # Quick hack: iTerms default window only supports up to 11 rows and 22 columns
76
+ # If we surpass either one, we resort to full screen.
77
+ if @rows > 11 or @columns > 22 then
78
+ @i2_options.first[:fullscreen] = true
79
+ end
80
+ end
81
+
82
+ def split_session
83
+ left = @pane_menu.menu_items["Select Pane Left"]
84
+ right = @pane_menu.menu_items["Select Pane Right"]
85
+ up = @pane_menu.menu_items["Select Pane Above"]
86
+ down = @pane_menu.menu_items["Select Pane Below"]
87
+
88
+ split_vert = lambda { @window.current_session.split_vertically_with_same_profile }
89
+ split_hori = lambda { @window.current_session.split_horizontally_with_same_profile }
90
+
91
+ splitmap = {
92
+ :column => {0 => split_vert, 1 => left, 2 => split_hori, 3=> right, :x => @columns, :y => @rows},
93
+ :row => {0 => split_hori, 1=> up, 2 => split_vert, 3=> down, :x => @rows, :y => @columns}
94
+ }
95
+ splitconfig = splitmap[@i2_options.first[:direction]]
96
+
97
+ first = true
98
+ 2.upto splitconfig[:x] do
99
+ splitconfig[0].call
100
+ end
101
+ 2.upto splitconfig[:y] do
102
+ 1.upto splitconfig[:x] do
103
+ splitconfig[1].click
104
+ first = false
105
+ end
106
+ splitconfig[:x].times do |x|
107
+ splitconfig[2].call
108
+ splitconfig[3].click
109
+ end
110
+ end
111
+ end
112
+
113
+ def enable_broadcast
114
+ @sys_events.keystroke "I", :using => :command_down
115
+ sleep 0.5
116
+ @sys_events.keystroke "\r"
117
+ end
118
+
119
+ def start_ssh
120
+ old_size = 0
121
+
122
+ 1.upto(@rows*@columns) do |i|
123
+ tab = @window.current_tab
124
+ session = tab.sessions[i]
125
+ session.write :text => "#{@shell} -l"
126
+
127
+ # Without the tab flag, combine all servers and clusters into one window
128
+ if !@servers.empty? && (i - old_size) > @servers.first.size && !@i2_options.first[:tabs]
129
+ old_size = @servers.first.size
130
+ @servers.shift
131
+ @i2_options.shift
132
+ @ssh_environment.shift
133
+ end
134
+
135
+ if @servers.empty?
136
+ server = nil
137
+ else
138
+ server = @servers.first[i-old_size-1]
139
+ end
140
+
141
+
142
+ if server then
143
+ send_env = ""
144
+
145
+ if @i2_options.first[:rank] then
146
+ @ssh_environment.first['LC_RANK'] = i-1
147
+ end
148
+
149
+ if !@ssh_environment.empty? && !@ssh_environment.first.empty? then
150
+ send_env = "-o SendEnv=#{@ssh_environment.first.keys.join(",")}"
151
+ session.write :text => "#{@ssh_environment.first.map{|k,v| "export #{k}=#{v}"}.join('; ')}"
152
+ end
153
+ if @i2_options.first[:sleep] then
154
+ sleep @i2_options.first[:sleep] * i
155
+ end
156
+
157
+ session.write :text => "unset HISTFILE && echo -e \"\\033]50;SetProfile=#{@profile}\\a\" && #{@ssh_prefix} #{send_env} #{server}"
158
+ else
159
+
160
+ session.write :text => "unset HISTFILE && echo -e \"\\033]50;SetProfile=#{@profile}\\a\""
161
+ sleep 0.3
162
+ session.foreground_color.set ([65535,0,0])
163
+ session.write :text => "stty -isig -icanon -echo && echo -e '#{"\n"*100}UNUSED' && cat > /dev/null"
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'i2c2'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestI2c2 < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i2c2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.99.0
5
+ platform: ruby
6
+ authors:
7
+ - dx7
8
+ - Wouter de Bie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2019-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: jeweler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 2.1.2
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 2.1.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: shoulda
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: builder
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rb-scpt
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.0.1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 1.0.1
84
+ description: csshX like cluster ssh using iTerm2 panes
85
+ email: dx7@pm.me
86
+ executables:
87
+ - i2c2
88
+ extensions: []
89
+ extra_rdoc_files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ files:
93
+ - ".document"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - VERSION
100
+ - bin/i2c2
101
+ - i2c2.gemspec
102
+ - lib/i2c2.rb
103
+ - test/helper.rb
104
+ - test/test_i2c2.rb
105
+ homepage: http://github.com/dx7/i2c2
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.8
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: csshX like cluster ssh using iTerm2 panes
129
+ test_files: []