tmuxall 0.0.1

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.
@@ -0,0 +1,10 @@
1
+ tmp/
2
+ .DS_Store
3
+ .tags*
4
+ .rvmrc
5
+ .exrc
6
+ nohup.out
7
+ pkg/
8
+ coverage/
9
+ *.sublime-project
10
+ *.sublime-workspace
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tmuxall (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.0.3)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ rake
16
+ tmuxall!
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vladimir Yarotsky
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Tmuxall
2
+
3
+ An utility to launch multiple commands inside tmux session with custom layouts
4
+
5
+ ## Installation
6
+
7
+ $ gem install tmuxall
8
+
9
+ ## Usage
10
+
11
+ Tmuxall accepts commands to execute either via parameters or via stdin
12
+
13
+ Example usage:
14
+
15
+ $ tmuxall 'echo hello' 'echo bye' 'ls -la'
16
+
17
+ $ cat | tmuxall
18
+ > echo hello
19
+ > echo bye
20
+ > ls \
21
+ > -la
22
+ > <Ctrl-D>
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+ require 'tmuxall/layouts'
7
+
8
+ options = OpenStruct.new
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = <<-HELP
12
+ An utility to run a bunch of commands in mulitiple tmux panes.
13
+
14
+ Usage: echo 'echo it works' | tmuxall -n WINDOW_NAME
15
+
16
+ Commands can be passed via stdin or arguments
17
+
18
+ HELP
19
+
20
+ opts.separator "Options:"
21
+
22
+ opts.on("-n", "--window-name NAME", "New tmux window name") { |v| options.window_name = v }
23
+ opts.on("--dry-run", "Only show what would be done") { |v| options.dry_run = true }
24
+ end.parse!
25
+
26
+ def parse_stdin_commands
27
+ commands = []
28
+ buffer = ""
29
+ STDIN.each_line do |line|
30
+ if line =~ /\\$/
31
+ buffer << line
32
+ next
33
+ end
34
+ buffer << line.rstrip
35
+ commands << buffer.dup
36
+ buffer.clear
37
+ end
38
+ commands
39
+ end
40
+
41
+ begin
42
+ commands = ARGV.empty? ? parse_stdin_commands : ARGV
43
+ Tmuxall::Layouts::TwoColumns.new(commands, options).run
44
+ rescue => e
45
+ warn <<-ERR.rstrip
46
+ An error occured: #{e.message}.
47
+ Run tmuxall --help for instructions
48
+ ERR
49
+
50
+ warn e.backtrace.join("\n") if ENV["DEBUG"]
51
+
52
+ exit 1
53
+ end
54
+
@@ -0,0 +1,4 @@
1
+ require "tmuxall/version"
2
+
3
+ module Tmuxall
4
+ end
@@ -0,0 +1,6 @@
1
+ module Tmuxall
2
+ module Layouts
3
+ end
4
+ end
5
+
6
+ require 'tmuxall/layouts/two_columns'
@@ -0,0 +1,50 @@
1
+ module Tmuxall
2
+ module Layouts
3
+
4
+ class Base
5
+ def initialize(commands, options)
6
+ @commands = Array(commands)
7
+
8
+ if @commands.empty?
9
+ raise ArgumentError, "No commands to run"
10
+ end
11
+
12
+ @options = options
13
+ @panes_count = @commands.size
14
+ end
15
+
16
+ def run
17
+ ensure_tmux
18
+ create_window
19
+ create_panes
20
+ run_commands_in_panes
21
+ end
22
+
23
+ private
24
+
25
+ def ensure_tmux
26
+ if ENV["TMUX"].nil?
27
+ raise "Must be run in tmux session"
28
+ end
29
+ end
30
+
31
+ def create_window
32
+ name = @options.window_name || "tmuxall"
33
+ tmux "new-window -n #{name}"
34
+ end
35
+
36
+ def create_panes
37
+ raise NotImplementedError
38
+ end
39
+
40
+ def run_commands_in_panes
41
+ raise NotImplementedError
42
+ end
43
+
44
+ def tmux(cmd)
45
+ @options.dry_run ? puts(cmd) : `tmux #{cmd}`
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,31 @@
1
+ require 'tmuxall/layouts/base'
2
+
3
+ module Tmuxall
4
+ module Layouts
5
+
6
+ class TwoColumns < Base
7
+ def create_panes
8
+ (1..(@panes_count - 2)).step(2).each do |n|
9
+ tmux "splitw"
10
+ tmux "selectl even-vertical"
11
+ end
12
+
13
+ if @panes_count > 1
14
+ (1...@panes_count).step(2).each do |n|
15
+ tmux "selectp -t #{n}"
16
+ tmux "splitw -h"
17
+ end
18
+ end
19
+ end
20
+
21
+ def run_commands_in_panes
22
+ (1..@panes_count).each do |n|
23
+ tmux "selectp -t #{n}"
24
+ tmux %Q{send-keys "#{@commands[n - 1]}\n"}
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,3 @@
1
+ module Tmuxall
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tmuxall/version'
5
+ require 'date'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "tmuxall"
9
+ gem.version = Tmuxall::VERSION
10
+ gem.date = Date.today.to_s
11
+ gem.authors = ["Vladimir Yarotsky"]
12
+ gem.email = ["vladimir.yarotsky@gmail.com"]
13
+
14
+ gem.summary = <<DESC
15
+ An utility to launch multiple commands inside tmux session with custom layouts
16
+ DESC
17
+
18
+ gem.homepage = "https://github.com/v-yarotsky/tmuxall"
19
+
20
+ gem.files = `git ls-files`.split($/)
21
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ["lib"]
24
+
25
+ gem.add_development_dependency("rake")
26
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tmuxall
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Vladimir Yarotsky
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ prerelease: false
30
+ description:
31
+ email:
32
+ - vladimir.yarotsky@gmail.com
33
+ executables:
34
+ - tmuxall
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/tmuxall
45
+ - lib/tmuxall.rb
46
+ - lib/tmuxall/layouts.rb
47
+ - lib/tmuxall/layouts/base.rb
48
+ - lib/tmuxall/layouts/two_columns.rb
49
+ - lib/tmuxall/version.rb
50
+ - tmuxall.gemspec
51
+ homepage: https://github.com/v-yarotsky/tmuxall
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ hash: 1989834141416195468
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ hash: 1989834141416195468
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.25
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: An utility to launch multiple commands inside tmux session with custom layouts
81
+ test_files: []