multish 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +152 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/multish +4 -0
- data/lib/multish.rb +125 -0
- data/lib/multish/version.rb +3 -0
- data/multish.gemspec +30 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 047ccfeb880c5b9ebabc0b394e72cfb0b7015ef8
|
4
|
+
data.tar.gz: d516b3e8dd2ad8f5020a682ec8668ce82007a4ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e3e57b936eba70f97d6430e63b96143994decc55c4d8fe7394b59caa032a11d37c18310584348571bd4eacc66656dc18f1d334e2ee7370c24162ef2fb21eff34
|
7
|
+
data.tar.gz: b721e8b5399007a3201c2ddc674e421844affcf7f43908420a10ca579bb9885c088ef560489a6df88e2452ed1256df39cae931397d39560db2af83786c9a8913
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
DisplayCopNames: true
|
4
|
+
|
5
|
+
Rails:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Style/SymbolArray:
|
9
|
+
Enabled: true
|
10
|
+
|
11
|
+
Style/FrozenStringLiteralComment:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/GuardClause:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/StringLiterals:
|
18
|
+
EnforcedStyle: single_quotes
|
19
|
+
|
20
|
+
Style/ClassAndModuleChildren:
|
21
|
+
Enabled: false
|
22
|
+
EnforcedStyle: compact
|
23
|
+
|
24
|
+
Style/SpaceInsideHashLiteralBraces:
|
25
|
+
EnforcedStyle: no_space
|
26
|
+
|
27
|
+
Style/AccessorMethodName:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Metrics/LineLength:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/IndentHash:
|
34
|
+
Enabled: false
|
35
|
+
EnforcedStyle: align_braces
|
36
|
+
|
37
|
+
Style/IndentationConsistency:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Style/TrailingCommaInLiteral:
|
41
|
+
EnforcedStyleForMultiline: comma
|
42
|
+
|
43
|
+
Style/NumericLiterals:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Lint/Void:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/Documentation:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
AccessModifierIndentation:
|
53
|
+
EnforcedStyle: outdent
|
54
|
+
|
55
|
+
Metrics/MethodLength:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Metrics/AbcSize:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Metrics/CyclomaticComplexity:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Metrics/PerceivedComplexity:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Style/PerlBackrefs:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Style/RegexpLiteral:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Lint/EndAlignment:
|
74
|
+
AutoCorrect: true
|
75
|
+
|
76
|
+
Lint/DefEndAlignment:
|
77
|
+
AutoCorrect: true
|
78
|
+
|
79
|
+
Style/RaiseArgs:
|
80
|
+
EnforcedStyle: compact
|
81
|
+
|
82
|
+
Style/FormatString:
|
83
|
+
EnforcedStyle: sprintf
|
84
|
+
|
85
|
+
Metrics/ClassLength:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
Style/Lambda:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
Metrics/ModuleLength:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
Rails/HasAndBelongsToMany:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
Style/EachWithObject:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
Metrics/ParameterLists:
|
101
|
+
Enabled: false
|
102
|
+
|
103
|
+
Style/ClassVars:
|
104
|
+
Enabled: false
|
105
|
+
|
106
|
+
Style/MultilineBlockChain:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
Style/PredicateName:
|
110
|
+
Enabled: false
|
111
|
+
|
112
|
+
Style/DoubleNegation:
|
113
|
+
Enabled: false
|
114
|
+
|
115
|
+
Style/InfiniteLoop:
|
116
|
+
Enabled: false
|
117
|
+
|
118
|
+
Style/AsciiComments:
|
119
|
+
Enabled: false
|
120
|
+
|
121
|
+
Style/NumericPredicate:
|
122
|
+
Enabled: false
|
123
|
+
|
124
|
+
Style/TernaryParentheses:
|
125
|
+
Enabled: false
|
126
|
+
|
127
|
+
Style/FileName:
|
128
|
+
Enabled: false
|
129
|
+
|
130
|
+
Style/IfUnlessModifier:
|
131
|
+
Enabled: false
|
132
|
+
|
133
|
+
Style/RedundantSelf:
|
134
|
+
Enabled: false
|
135
|
+
|
136
|
+
Lint/AssignmentInCondition:
|
137
|
+
Enabled: false
|
138
|
+
|
139
|
+
Lint/LiteralInCondition:
|
140
|
+
Enabled: false
|
141
|
+
|
142
|
+
Style/For:
|
143
|
+
Enabled: false
|
144
|
+
|
145
|
+
Style/TrivialAccessors:
|
146
|
+
Enabled: false
|
147
|
+
|
148
|
+
Style/RescueModifier:
|
149
|
+
Enabled: false
|
150
|
+
|
151
|
+
Style/GlobalVars:
|
152
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Tomasz Dąbrowski
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Multish
|
2
|
+
|
3
|
+
Allows to run multiple commands in one terminal, side by side.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'multish'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install multish
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Example:
|
24
|
+
|
25
|
+
$ multish 'find ..' 'for i in `seq 1 10`; do echo $i; sleep 1; done' 'curl -v http://google.com'
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/multish.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'multish'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/multish
ADDED
data/lib/multish.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'multish/version'
|
2
|
+
|
3
|
+
require 'curses'
|
4
|
+
require 'open3'
|
5
|
+
|
6
|
+
class MultishItem
|
7
|
+
attr_reader :command
|
8
|
+
|
9
|
+
def initialize(command, index, count)
|
10
|
+
@command = command
|
11
|
+
@index = index
|
12
|
+
@count = count
|
13
|
+
end
|
14
|
+
|
15
|
+
def width
|
16
|
+
(Curses.cols / @count).floor
|
17
|
+
end
|
18
|
+
|
19
|
+
def height
|
20
|
+
Curses.lines
|
21
|
+
end
|
22
|
+
|
23
|
+
def left
|
24
|
+
width * @index
|
25
|
+
end
|
26
|
+
|
27
|
+
def top
|
28
|
+
0
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_window!
|
32
|
+
@nav_window = Curses::Window.new(1, width - 1, top, left)
|
33
|
+
@window = Curses::Window.new(height - 1, width - 1, top + 1, left)
|
34
|
+
@window.scrollok(true)
|
35
|
+
update_title!
|
36
|
+
end
|
37
|
+
|
38
|
+
def color_code
|
39
|
+
if !@wait_thr
|
40
|
+
4
|
41
|
+
elsif finished?
|
42
|
+
errored? ? 3 : 2
|
43
|
+
else
|
44
|
+
4
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def errored?
|
49
|
+
@exit_code && !(@exit_code == 0)
|
50
|
+
end
|
51
|
+
|
52
|
+
def update_title!
|
53
|
+
@nav_window.setpos(0, 0)
|
54
|
+
@nav_window.attron(Curses.color_pair(color_code) | Curses::A_REVERSE | Curses::A_BOLD)
|
55
|
+
text = !finished? ? "$ #{command}" : "[ #{command} ] -> #{@exit_code}"
|
56
|
+
@nav_window.addstr(text.ljust(width - 1))
|
57
|
+
@nav_window.refresh
|
58
|
+
end
|
59
|
+
|
60
|
+
def open_process!
|
61
|
+
@stdin, @stdout, @stderr, @wait_thr = Open3.popen3(@command)
|
62
|
+
@stdin.close
|
63
|
+
end
|
64
|
+
|
65
|
+
def streams
|
66
|
+
[@stdout, @stderr]
|
67
|
+
end
|
68
|
+
|
69
|
+
def try_update(fd)
|
70
|
+
return unless fd == @stdout || fd == @stderr
|
71
|
+
line = fd.gets
|
72
|
+
print(line) if line
|
73
|
+
end
|
74
|
+
|
75
|
+
def print(text)
|
76
|
+
@window.addstr(text)
|
77
|
+
@window.refresh
|
78
|
+
end
|
79
|
+
|
80
|
+
def finished?
|
81
|
+
return false unless @wait_thr
|
82
|
+
ret = !@wait_thr.alive?
|
83
|
+
if ret && !@exit_code
|
84
|
+
@exit_code = @wait_thr.value
|
85
|
+
end
|
86
|
+
ret
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class Multish
|
91
|
+
def self.run!(args)
|
92
|
+
self.new.run!(args)
|
93
|
+
end
|
94
|
+
|
95
|
+
def run!(args)
|
96
|
+
@commands = args.each_with_index.map { |arg, index| MultishItem.new(arg, index, args.count) }
|
97
|
+
Curses.init_screen
|
98
|
+
Curses.start_color
|
99
|
+
Curses.curs_set(0)
|
100
|
+
Curses.init_pair(2, Curses::COLOR_WHITE, Curses::COLOR_GREEN)
|
101
|
+
Curses.init_pair(3, Curses::COLOR_WHITE, Curses::COLOR_RED)
|
102
|
+
Curses.init_pair(4, Curses::COLOR_WHITE, Curses::COLOR_BLACK)
|
103
|
+
Curses.use_default_colors
|
104
|
+
Curses.cbreak
|
105
|
+
@commands.each(&:create_window!)
|
106
|
+
@commands.each(&:open_process!)
|
107
|
+
fdlist = @commands.flat_map(&:streams)
|
108
|
+
begin
|
109
|
+
while true
|
110
|
+
fdlist.reject!(&:closed?)
|
111
|
+
break if fdlist.empty?
|
112
|
+
ready = IO.select(fdlist)[0]
|
113
|
+
ready.each do |fd|
|
114
|
+
@commands.each { |command| command.try_update(fd) }
|
115
|
+
end
|
116
|
+
@commands.each(&:update_title!)
|
117
|
+
break if @commands.all?(&:finished?)
|
118
|
+
end
|
119
|
+
ensure
|
120
|
+
Curses.curs_set(1)
|
121
|
+
Curses.close_screen
|
122
|
+
exit(@commands.any?(&:errored?) ? 1 : 0)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
data/multish.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'multish/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'multish'
|
8
|
+
spec.version = Multish::VERSION
|
9
|
+
spec.authors = ['Tomasz Dąbrowski']
|
10
|
+
spec.email = ['t.dabrowski@rock-hard.eu']
|
11
|
+
|
12
|
+
spec.summary = 'Run multiple commands in one terminal, side by side'
|
13
|
+
spec.description = 'Run multiple commands in one terminal, side by side'
|
14
|
+
spec.homepage = 'http://github.com/dabroz/multish'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.47.1'
|
28
|
+
|
29
|
+
spec.add_runtime_dependency 'curses'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multish
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomasz Dąbrowski
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.47.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.47.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: curses
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Run multiple commands in one terminal, side by side
|
84
|
+
email:
|
85
|
+
- t.dabrowski@rock-hard.eu
|
86
|
+
executables:
|
87
|
+
- multish
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- exe/multish
|
102
|
+
- lib/multish.rb
|
103
|
+
- lib/multish/version.rb
|
104
|
+
- multish.gemspec
|
105
|
+
homepage: http://github.com/dabroz/multish
|
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.5.1
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Run multiple commands in one terminal, side by side
|
129
|
+
test_files: []
|