terminal_velocity 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ Spec::Rake::SpecTask.new do |t|
19
19
  end
20
20
 
21
21
  GEM = "terminal_velocity"
22
- GEM_VERSION = "0.0.1"
22
+ GEM_VERSION = "0.0.2"
23
23
  AUTHOR = "Corey Donohoe"
24
24
  EMAIL = "atmos@atmos.org"
25
25
  HOMEPAGE = "http://www.atmos.org/terminal-velocity/"
@@ -1,5 +1,10 @@
1
1
  require 'tmpdir'
2
+ require 'digest/sha1'
3
+
4
+ require File.dirname(__FILE__) + "/terminal_velocity/templates"
2
5
 
3
6
  module TerminalVelocity
7
+ def self.launch(username, hostnames)
8
+ TerminalVelocity::Templates::AppleScripter.run(username, hostnames)
9
+ end
4
10
  end
5
-
@@ -0,0 +1,71 @@
1
+ module TerminalVelocity
2
+ module Templates
3
+ class Runner
4
+ def self.run(username, hostnames)
5
+ users_at_hostnames = hostnames.map { |hostname| "#{username}@#{hostname}" }
6
+ new(users_at_hostnames).run
7
+ end
8
+
9
+ def initialize(users_at_hostnames)
10
+ @users_at_hostnames = users_at_hostnames
11
+ end
12
+
13
+ def run
14
+ generate_script
15
+ launch
16
+ end
17
+
18
+ private
19
+ def ssh_command(user_at_hostname)
20
+ "clear; ssh -o StrictHostKeyChecking=no #{user_at_hostname}"
21
+ end
22
+
23
+ def generate_script
24
+ File.open(script_filename, "w") do |fp|
25
+ fp.write(ERB.new(File.read(template)).result(binding))
26
+ end
27
+ end
28
+
29
+ def launch
30
+ %x{#{launcher_script} "#{script_filename}" 2>/dev/null}
31
+ end
32
+
33
+ def script_filename
34
+ "#{Dir.tmpdir}.#{script_sha1}.terms"
35
+ end
36
+
37
+ def script_sha1
38
+ @script_sha1 ||= Digest::SHA1.hexdigest(Time.now.to_f.to_s)
39
+ end
40
+
41
+ def launcher_script
42
+ raise ArgumentError, "implement #launcher_script"
43
+ end
44
+
45
+ def template
46
+ raise ArgumentError, "implement #template"
47
+ end
48
+ end
49
+
50
+ class AppleScripter < Runner
51
+ def launcher_script
52
+ "osascript"
53
+ end
54
+
55
+ def template
56
+ File.join(File.dirname(__FILE__), "templates", "applescript.ssh.erb")
57
+ end
58
+ end
59
+
60
+ class Screen < Runner
61
+ def launcher_script
62
+ "screen -S terminal-velocity-#{script_sha1} -c"
63
+ end
64
+
65
+ def template
66
+ File.join(File.dirname(__FILE__), "templates", "screenrc.erb")
67
+ end
68
+ end
69
+ end
70
+ end
71
+
@@ -0,0 +1,66 @@
1
+ global window_id
2
+ global window_name
3
+ set window_id to 0
4
+ set window_name to ""
5
+
6
+ --
7
+ -- A sub-routine for selecting a sub-menu item in an application
8
+ -- http://www.macosxautomation.com/applescript/uiscripting/index.html
9
+ on do_submenu(app_name, menu_name, menu_item, submenu_item)
10
+ try
11
+ -- bring the target application to the front
12
+ tell application app_name
13
+ activate
14
+ end tell
15
+ tell application "System Events"
16
+ tell process app_name
17
+ tell menu bar 1
18
+ tell menu bar item menu_name
19
+ tell menu menu_name
20
+ tell menu item menu_item
21
+ tell menu menu_item
22
+ click menu item submenu_item
23
+ end tell
24
+ end tell
25
+ end tell
26
+ end tell
27
+ end tell
28
+ end tell
29
+ end tell
30
+ return true
31
+ on error error_message
32
+ return false
33
+ end try
34
+ end do_submenu
35
+
36
+ -- MAINLINE
37
+ tell application "Terminal"
38
+ activate
39
+
40
+ -- make a new window with the execution of a trivial command
41
+ set tabOffset to 0
42
+ set windowOffset to 1
43
+ my do_submenu("Terminal", "Shell", "New Window", "Pro")
44
+
45
+ -- load up the window id of the window we just created
46
+ set window_id to id of first window whose frontmost is true
47
+ set tab_count to count of tabs of window id window_id of application "Terminal"
48
+
49
+ -- make tabs 2, 3 and 4
50
+ repeat with i from 1 to (<%= @users_at_hostnames.size %> - windowOffset)
51
+ my do_submenu("Terminal", "Shell", "New Tab", "Pro")
52
+ end repeat
53
+
54
+ <% @users_at_hostnames.each_with_index do |user_at_hostname, i| %>
55
+ set curTab to tab (<%= i %> + tabOffset + tab_count) of window id window_id of application "Terminal"
56
+ set cmd to "clear; <%= ssh_command(user_at_hostname) %>"
57
+ do script cmd in curTab
58
+ <% end %>
59
+
60
+ -- resize
61
+ set region to the bounds of window id window_id of application "Terminal"
62
+ set x to item 1 of region
63
+ set y to item 2 of region
64
+ set w to item 3 of region
65
+ -- set the bounds of the first window to {x,y,w,640}
66
+ end tell
@@ -0,0 +1,8 @@
1
+ <%= File.read("#{ENV["HOME"]}/.screenrc") if File.exists?("#{ENV["HOME"]}/.screenrc") %>
2
+
3
+ defscrollback 1024
4
+
5
+ <% @users_at_hostnames.each do |user_at_hostname| %>
6
+ screen -t '<%= user_at_hostname %>' 0
7
+ stuff "<%= ssh_command(user_at_hostname) %>\015"
8
+ <% end %>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal_velocity
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Corey Donohoe
@@ -32,6 +32,8 @@ files:
32
32
  - README.md
33
33
  - Rakefile
34
34
  - lib/terminal_velocity/templates/applescript.ssh.erb
35
+ - lib/terminal_velocity/templates/screenrc.erb
36
+ - lib/terminal_velocity/templates.rb
35
37
  - lib/terminal_velocity.rb
36
38
  has_rdoc: true
37
39
  homepage: http://www.atmos.org/terminal-velocity/