divide 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +7 -0
- data/README.md +25 -0
- data/Rakefile +3 -0
- data/bin/divide +4 -0
- data/divide.gemspec +21 -0
- data/lib/divide.rb +29 -0
- data/lib/divide/extractor.rb +34 -0
- data/lib/divide/terminal_bridge.rb +40 -0
- data/lib/divide/version.rb +3 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 61c2bb7c29d7587d40f76bf342714e839bf1f579
|
4
|
+
data.tar.gz: d1fb8ec3ac33f6fa0424eb0e820f5078432e732d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d889eb570a31453eebfb0ea9ec3071782e5a686ccdd5d05e6a17d1eedc42494c9abc6639103993ba2f168d85e4b5bb2d2b411bf39bc8dc78bd8581996860fca8
|
7
|
+
data.tar.gz: 0289c2c966d691a89850c063db86dc82446609037cd2a12ccbf121c200c166864011104ddcb98deb241e2bf85fdb8d4e1030a1f2daa0e56f1900320448972140
|
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2013 Etienne Lemay
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Divide
|
2
|
+
Start Procfile processes in different Terminal.app tabs
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
```
|
6
|
+
$ gem install divide
|
7
|
+
```
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
```
|
11
|
+
$ divide
|
12
|
+
$ divide -p 1337
|
13
|
+
```
|
14
|
+
## License
|
15
|
+
MIT (See [LICENSE][])
|
16
|
+
|
17
|
+
---
|
18
|
+
|
19
|
+
I’m well aware of [foreman][], but it starts all processes in the same tab which can be inconvenient.<br>
|
20
|
+
I’m well aware of [tmux][], but obviously not everyone’s using it (if you do, check out [teamocil][]).
|
21
|
+
|
22
|
+
[LICENSE]: /LICENSE.md
|
23
|
+
[foreman]: https://github.com/dollar/foreman
|
24
|
+
[tmux]: http://tmux.sourceforge.net
|
25
|
+
[teamocil]: https://github.com/remiprev/teamocil
|
data/Rakefile
ADDED
data/bin/divide
ADDED
data/divide.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../lib/divide/version', __FILE__)
|
2
|
+
|
3
|
+
spec = Gem::Specification.new do |s|
|
4
|
+
s.name = 'divide'
|
5
|
+
s.author = 'Etienne Lemay'
|
6
|
+
s.email = 'etienne@heliom.ca'
|
7
|
+
s.homepage = 'https://github.com/EtienneLem/'
|
8
|
+
s.summary = 'Start Procfile processes in different Terminal.app tabs'
|
9
|
+
|
10
|
+
s.version = Divide::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
|
13
|
+
s.files = %w(LICENSE.md README.md Rakefile divide.gemspec)
|
14
|
+
s.files += Dir.glob("lib/**/*.rb")
|
15
|
+
s.files += Dir.glob("bin/**/*")
|
16
|
+
|
17
|
+
s.bindir = 'bin'
|
18
|
+
s.executables << 'divide'
|
19
|
+
|
20
|
+
s.require_paths << 'lib'
|
21
|
+
end
|
data/lib/divide.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'divide/version'
|
2
|
+
require 'divide/extractor'
|
3
|
+
require 'divide/terminal_bridge'
|
4
|
+
|
5
|
+
module Divide
|
6
|
+
def self.run(argv)
|
7
|
+
@options = argv.each_slice(2).to_a
|
8
|
+
terminal.exec(processes)
|
9
|
+
1
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.processes
|
13
|
+
no_profile unless extracted_processes = extractor.extract_processes!
|
14
|
+
extracted_processes.to_a.map { |a| a[1] }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.no_profile
|
18
|
+
puts "#{Dir.pwd}: There is no Procfile in this directory"
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.terminal
|
23
|
+
@terminal ||= Divide::TerminalBridge.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.extractor
|
27
|
+
@extractor ||= Divide::Extractor.new(@options)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Divide::Extractor
|
4
|
+
def initialize(options=[])
|
5
|
+
@procfile_content = File.read('./Procfile') rescue ''
|
6
|
+
@options = options
|
7
|
+
|
8
|
+
overwrite_options
|
9
|
+
overwrite_port
|
10
|
+
end
|
11
|
+
|
12
|
+
def overwrite_options
|
13
|
+
splitted_procfile = @procfile_content.split(/\s/)
|
14
|
+
|
15
|
+
@options.each do |option|
|
16
|
+
key = option[0]
|
17
|
+
value = option[1]
|
18
|
+
|
19
|
+
key_index = splitted_procfile.index(key)
|
20
|
+
value_to_overwrite = splitted_procfile[key_index + 1]
|
21
|
+
|
22
|
+
@procfile_content.sub!(value_to_overwrite, value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def overwrite_port
|
27
|
+
@procfile_content.sub!('$PORT', ENV['PORT'] || '5000')
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_processes!
|
31
|
+
return nil if @procfile_content.empty?
|
32
|
+
YAML.load(@procfile_content)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Divide::TerminalBridge
|
2
|
+
def apple_script(cmd)
|
3
|
+
cmd = cmd.join("' -e '") if cmd.is_a?(Array)
|
4
|
+
`osascript -e '#{cmd}'`
|
5
|
+
end
|
6
|
+
|
7
|
+
def tell_terminal(cmd)
|
8
|
+
%(tell app "Terminal" to #{cmd})
|
9
|
+
end
|
10
|
+
|
11
|
+
def do_script(script)
|
12
|
+
tell_terminal %(do script "#{script}" in front window)
|
13
|
+
end
|
14
|
+
|
15
|
+
def keystroke(app, key)
|
16
|
+
splits = key.split('+')
|
17
|
+
|
18
|
+
if splits.length > 1
|
19
|
+
modifier_key = splits[0]
|
20
|
+
key = splits[1]
|
21
|
+
else
|
22
|
+
modifier_key = nil
|
23
|
+
key = splits[0]
|
24
|
+
end
|
25
|
+
|
26
|
+
modifier = modifier_key ? " using #{modifier_key} down" : ''
|
27
|
+
%(tell app "System Events" to tell process "#{app}" to keystroke "#{key}"#{modifier})
|
28
|
+
end
|
29
|
+
|
30
|
+
def exec(commands)
|
31
|
+
scripts = commands.map { |c| do_script(c) }
|
32
|
+
scripts_with_new_tabs = insert_between(scripts, keystroke('Terminal', 'command+t'))
|
33
|
+
|
34
|
+
apple_script(scripts_with_new_tabs)
|
35
|
+
end
|
36
|
+
|
37
|
+
def insert_between(scripts, insert_between)
|
38
|
+
scripts.flat_map { |s| [s, insert_between] }[0...-1]
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: divide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Etienne Lemay
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: etienne@heliom.ca
|
15
|
+
executables:
|
16
|
+
- divide
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE.md
|
21
|
+
- README.md
|
22
|
+
- Rakefile
|
23
|
+
- divide.gemspec
|
24
|
+
- lib/divide/extractor.rb
|
25
|
+
- lib/divide/terminal_bridge.rb
|
26
|
+
- lib/divide/version.rb
|
27
|
+
- lib/divide.rb
|
28
|
+
- bin/divide
|
29
|
+
homepage: https://github.com/EtienneLem/
|
30
|
+
licenses: []
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.0.0
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Start Procfile processes in different Terminal.app tabs
|
53
|
+
test_files: []
|