threeman 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bb5fce8492e5868a3b033affa86b026f3f90c3a
4
- data.tar.gz: 36f664f9664b76e5b8bf0cda32fa64c1e9ec30f0
3
+ metadata.gz: 765f19786b13a7cb5a023f159e8d430d1a0e75a3
4
+ data.tar.gz: f86d28d400765992a9de7df2323f1b414f30b493
5
5
  SHA512:
6
- metadata.gz: 6fdc1645b9da3d0e35f64503f578d9309346e9747551ff521708540eb039f68b181809cd47fbfe334cf6d2b93fb3de9cb334b616731f08b68e39dcb36cd3750b
7
- data.tar.gz: 1f6cf541d3aff2685ac08ac7695f23e88ac4d01686e1110333c001cae005cbc75b1f2371bf6249ce563aa2dbfa26964184fe7940f039696f11eed77508b95263
6
+ metadata.gz: ddbce7064da10dfb54e0c9b5951c0432a185e015b08de43991b310d66bca1f68ce8220f78cf348db3262b6d5a49ec49829cc58eb288775dbd81ed944c16182b4
7
+ data.tar.gz: 2150184f85c6c89adc40105462d305db012073c82102bbb910691c03d2142ae5f85b78550b0c4501ad77b6d1a32913fd55a72edf8f4c931cef805bb2d0ce96ed
@@ -0,0 +1,14 @@
1
+ # 0.2.0 - March 29, 2016
2
+
3
+ * Refactor into multiple frontends
4
+ * Add support for Mac OS X Terminal.app
5
+
6
+ # 0.1.1 - March 28, 2016
7
+
8
+ * Add license
9
+ * Add code of conduct
10
+ * Change ownership to patientslikeme
11
+
12
+ # 0.1.0 - March 28, 2016
13
+
14
+ * First release
data/README.md CHANGED
@@ -1,13 +1,18 @@
1
1
  # Threeman
2
2
 
3
- Threeman is an alternative to [Foreman](https://github.com/ddollar/foreman) for Mac users. Rather than running all the commands together in one terminal, it opens a new [iTerm 2](https://www.iterm2.com) window with each command in a tab. The benefits of this are:
3
+ Threeman is an alternative to [Foreman](https://github.com/ddollar/foreman). Rather than running all the commands together in one terminal, it opens a new terminal window with each command in a tab. The benefits of this are:
4
4
 
5
- * iTerm 2 will notify you using an icon when there's new output from each command
5
+ * Your terminal app will notify you using an icon when there's new output from each command
6
6
  * Because your command's input and output aren't being intercepted by Foreman, you can use [Pry](http://pryrepl.org)
7
7
 
8
+ Threeman also has an extensible architecture to allow it to support multiple terminal apps. Right now, it supports:
9
+
10
+ * iTerm 2.9 and above
11
+ * Mac OS X's built-in Terminal app
12
+
8
13
  ## Installation
9
14
 
10
- Make sure you have [iTerm 2](https://www.iterm2.com/downloads.html) at least version 2.9 installed.
15
+ Make sure you have a supported terminal app installed.
11
16
 
12
17
  Run:
13
18
 
@@ -19,7 +24,7 @@ From your app's directory (with a Procfile in it), run:
19
24
 
20
25
  $ threeman
21
26
 
22
- Threeman will open a new iTerm 2 window with each of your Procfile commands running in a separate tab.
27
+ Threeman will open a new terminal window with each of your Procfile commands running in a separate tab.
23
28
 
24
29
  ## Development
25
30
 
@@ -1,43 +1,63 @@
1
- require 'foreman/procfile'
2
- require 'shellwords'
3
- require 'rb-scpt'
1
+ require 'threeman/procfile'
4
2
  require 'thor'
5
3
 
6
4
  module Threeman
5
+ FRONTENDS = {
6
+ :iterm3 => lambda {
7
+ require 'threeman/frontends/iterm3'
8
+ Threeman::Frontends::Iterm3.new
9
+ },
10
+ :mac_terminal => lambda {
11
+ require 'threeman/frontends/mac_terminal'
12
+ Threeman::Frontends::MacTerminal.new
13
+ }
14
+ }
15
+
7
16
  class CLI < Thor
8
17
  default_task :start
9
18
 
10
19
  desc "start", "Start the application"
20
+ option :frontend
11
21
  def start
12
- iterm = Appscript.app("iTerm")
13
- iterm.activate
14
- window = iterm.create_window_with_default_profile
15
-
16
22
  pwd = Dir.pwd
23
+ procfile = Threeman::Procfile.new(File.expand_path("Procfile", pwd))
24
+ commands = procfile.commands(pwd)
17
25
 
18
- procfile = Foreman::Procfile.new(File.expand_path("Procfile", pwd))
19
- is_first = true
20
- procfile.entries do |name, command|
21
- current_tab = if is_first
22
- window
23
- else
24
- window.create_tab_with_default_profile
25
- end
26
-
27
- run_command(current_tab.current_session, name, pwd, command)
28
- is_first = false
26
+ frontend_name = options[:frontend] || auto_frontend
27
+ unless frontend_name
28
+ puts "Couldn't determine a frontend to use. Please specify one using --frontend."
29
+ print_valid_frontend_names
30
+ exit! 1
29
31
  end
32
+
33
+ frontend(frontend_name).run_commands(commands)
30
34
  end
31
35
 
32
36
  private
33
- def run_command(session, name, workdir, command)
34
- bash_script = [
35
- "echo -ne \"\\033]0;#{Shellwords.escape name}\\007\"",
36
- "cd #{workdir}",
37
- command
38
- ].join(" ; ")
39
-
40
- session.write(text: "bash -c #{Shellwords.escape bash_script}")
37
+ def frontend(name)
38
+ frontend_lambda = FRONTENDS[name.to_sym]
39
+ unless frontend_lambda
40
+ puts "No frontend named #{name}!"
41
+ print_valid_frontend_names
42
+ exit! 1
43
+ end
44
+
45
+ frontend_lambda.call
46
+ end
47
+
48
+ def auto_frontend
49
+ if File.exist?('/Applications/iTerm.app/Contents/Info.plist')
50
+ iterm_version = `defaults read /Applications/iTerm.app/Contents/Info.plist CFBundleShortVersionString`
51
+ return :iterm3 if iterm_version >= "2.9"
52
+ end
53
+
54
+ if File.exist?('/Applications/Utilities/Terminal.app/Contents/Info.plist')
55
+ return :mac_terminal
56
+ end
57
+ end
58
+
59
+ def print_valid_frontend_names
60
+ puts "Valid frontend names are: #{FRONTENDS.keys.sort.join(', ')}."
41
61
  end
42
62
  end
43
63
  end
@@ -0,0 +1,20 @@
1
+ require 'shellwords'
2
+
3
+ module Threeman
4
+ class Command
5
+ attr_accessor :name, :command, :workdir
6
+
7
+ def initialize(name, command, workdir)
8
+ @name = name
9
+ @command = command
10
+ @workdir = workdir
11
+ end
12
+
13
+ def bash_script
14
+ [
15
+ "cd #{workdir}",
16
+ command
17
+ ].join(" ; ")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require 'shellwords'
2
+
3
+ module Threeman
4
+ class Frontend
5
+ def run_commands(commands)
6
+ raise "Subclasses must implement #run_commands"
7
+ end
8
+
9
+ def bash_script(command)
10
+ [
11
+ "echo -ne \"\\033]0;#{Shellwords.escape command.name}\\007\"",
12
+ command.bash_script
13
+ ].join(" ; ")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require 'threeman/frontend'
2
+ begin
3
+ require 'rb-scpt'
4
+ rescue LoadError
5
+ puts "The iterm3 frontend for Threeman requires the rb-scpt gem. Install it using: gem install rb-scpt"
6
+ exit!
7
+ end
8
+
9
+ module Threeman
10
+ module Frontends
11
+ class Iterm3 < Threeman::Frontend
12
+ def run_commands(commands)
13
+ iterm = Appscript.app("iTerm")
14
+ iterm.activate
15
+ window = iterm.create_window_with_default_profile
16
+
17
+ commands.each_with_index do |command, index|
18
+ current_tab = if index == 0
19
+ window
20
+ else
21
+ window.create_tab_with_default_profile
22
+ end
23
+
24
+ run_command(current_tab.current_session, command)
25
+ end
26
+ end
27
+
28
+ private
29
+ def run_command(session, command)
30
+ session.write(text: "bash -c #{Shellwords.escape bash_script(command)}")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ require 'threeman/frontend'
2
+ begin
3
+ require 'rb-scpt'
4
+ rescue LoadError
5
+ puts "The mac_terminal frontend for Threeman requires the rb-scpt gem. Install it using: gem install rb-scpt"
6
+ exit!
7
+ end
8
+
9
+ module Threeman
10
+ module Frontends
11
+ class MacTerminal < Threeman::Frontend
12
+ def run_commands(commands)
13
+ events = Appscript.app("System Events")
14
+
15
+ terminal = Appscript.app("Terminal")
16
+ terminal.activate
17
+
18
+ terminal_controller = events.processes['Terminal']
19
+
20
+ commands.each_with_index do |command, index|
21
+ if index == 0
22
+ terminal.do_script("")
23
+ else
24
+ sleep 0.3 # Terminal is slow and its scripting API is prone to misbehavior; wait for it to finish doing the thing we just did
25
+
26
+ terminal_controller.keystroke("t", using: [:command_down])
27
+ terminal.do_script("", in: terminal.windows[0])
28
+ end
29
+
30
+ sleep 0.3
31
+ terminal_controller.keystroke(bash_cmd(command) + "\n")
32
+ end
33
+ end
34
+
35
+ private
36
+ def bash_cmd(command)
37
+ "bash -c #{Shellwords.escape bash_script(command)}"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ require 'foreman/procfile'
2
+ require 'threeman/command'
3
+
4
+ module Threeman
5
+ class Procfile < Foreman::Procfile
6
+ def commands(workdir)
7
+ commands = []
8
+
9
+ entries do |name, command|
10
+ commands << Threeman::Command.new(name, command, workdir)
11
+ end
12
+
13
+ commands
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Threeman
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,10 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency "rb-scpt"
23
22
  spec.add_dependency "foreman"
24
23
 
25
24
  spec.add_development_dependency "bundler", "~> 1.10"
26
25
  spec.add_development_dependency "rake", "~> 10.0"
27
26
  spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "rb-scpt"
28
29
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: threeman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nat Budin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-28 00:00:00.000000000 Z
11
+ date: 2016-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rb-scpt
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: foreman
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +66,34 @@ dependencies:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rb-scpt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: An alternative to Foreman for Mac users, which runs each command in a
84
98
  separate iTerm 2 tab
85
99
  email:
@@ -91,6 +105,7 @@ extra_rdoc_files: []
91
105
  files:
92
106
  - ".gitignore"
93
107
  - ".travis.yml"
108
+ - CHANGELOG.md
94
109
  - CODE_OF_CONDUCT.md
95
110
  - Gemfile
96
111
  - LICENSE
@@ -101,6 +116,11 @@ files:
101
116
  - exe/threeman
102
117
  - lib/threeman.rb
103
118
  - lib/threeman/cli.rb
119
+ - lib/threeman/command.rb
120
+ - lib/threeman/frontend.rb
121
+ - lib/threeman/frontends/iterm3.rb
122
+ - lib/threeman/frontends/mac_terminal.rb
123
+ - lib/threeman/procfile.rb
104
124
  - lib/threeman/version.rb
105
125
  - threeman.gemspec
106
126
  homepage: https://github.com/patientslikeme/threeman