terminal_multiplexer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +15 -0
- data/Guardfile +11 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/doc/examples/tmux_wrapper-thor.rb +19 -0
- data/doc/examples/tmux_wrapper.rb +8 -0
- data/env +19 -0
- data/lib/terminal-multiplexer/exceptions.rb +11 -0
- data/lib/terminal-multiplexer/session.rb +50 -0
- data/lib/terminal-multiplexer/version.rb +3 -0
- data/lib/terminal-multiplexer/window.rb +20 -0
- data/lib/terminal-multiplexer.rb +61 -0
- data/spec/session/session_spec.rb +66 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/terminal-multiplexer/terminal-multiplexer_spec.rb +59 -0
- data/spec/window/window_spec.rb +36 -0
- data/terminal_multiplexer.gemspec +21 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in terminal-multiplexer.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'guard' #, '0.8.8'
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'pry'
|
11
|
+
gem 'libnotify'
|
12
|
+
gem 'rb-inotify'
|
13
|
+
gem 'rb-readline'
|
14
|
+
gem 'fuubar'
|
15
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec',
|
5
|
+
:version => 2 ,
|
6
|
+
:cli => '--color --format Fuubar' do
|
7
|
+
watch(%r{^spec/.+_spec\.rb$})
|
8
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
11
|
+
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
terminal-multiplexer (3) -- easy to use wrapper for tmux
|
2
|
+
=========================================================
|
3
|
+
|
4
|
+
## DESCRIPTION
|
5
|
+
|
6
|
+
This is a wrapper for tmux to integrate easily in one's development workflow.
|
7
|
+
|
8
|
+
You should configure tmux via its config-file ".tmux.conf". You could use this
|
9
|
+
library to create sessions and windows in that sessions.
|
10
|
+
|
11
|
+
## SYNOPSIS
|
12
|
+
|
13
|
+
```bash
|
14
|
+
#require lib
|
15
|
+
require 'terminal-multiplexer'
|
16
|
+
#create new instance
|
17
|
+
tmux = Terminal::Multiplexer.new
|
18
|
+
#create new session to hold all windows
|
19
|
+
tmux.new_session
|
20
|
+
tmux.new_session('window_name','command')
|
21
|
+
#create new window
|
22
|
+
tmux.new_window
|
23
|
+
tmux.new_window('window_name','command')
|
24
|
+
#start tmux
|
25
|
+
tmux.start
|
26
|
+
```
|
27
|
+
|
28
|
+
## INSTALL
|
29
|
+
|
30
|
+
* `Packaged:`
|
31
|
+
|
32
|
+
```bash
|
33
|
+
gem install terminal_multiplexer
|
34
|
+
```
|
35
|
+
|
36
|
+
* `Source code:`
|
37
|
+
|
38
|
+
```bash
|
39
|
+
git clone https://github.com/maxmeyer/terminal_multiplexer.git
|
40
|
+
cd terminal_multiplexer
|
41
|
+
rake build
|
42
|
+
gem install pkg/terminal_multiplexer-xxxx
|
43
|
+
```
|
44
|
+
|
45
|
+
## EXAMPLES
|
46
|
+
|
47
|
+
Please see "doc/examples/" for example scripts.
|
48
|
+
|
49
|
+
## FURTHER READING
|
50
|
+
|
51
|
+
* http://tmux.sourceforge.net
|
52
|
+
|
53
|
+
|
54
|
+
## LICENSE
|
55
|
+
|
56
|
+
(c) 2012-, All rights reserved, Max Meyer
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'terminal-multiplexer'
|
5
|
+
|
6
|
+
class Default < Thor
|
7
|
+
desc "work" , "Start working environment"
|
8
|
+
def work
|
9
|
+
tmux = Terminal::Multiplexer.new
|
10
|
+
tmux.new_session
|
11
|
+
tmux.new_window
|
12
|
+
tmux.new_window
|
13
|
+
tmux.new_window
|
14
|
+
tmux.new_window('tests', 'guard')
|
15
|
+
tmux.start
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Default.start
|
data/env
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'terminal-multiplexer'
|
5
|
+
|
6
|
+
class Default < Thor
|
7
|
+
desc "work" , "Start working environment"
|
8
|
+
def work
|
9
|
+
tmux = Terminal::Multiplexer.new
|
10
|
+
tmux.new_session
|
11
|
+
tmux.new_window
|
12
|
+
tmux.new_window
|
13
|
+
tmux.new_window
|
14
|
+
tmux.new_window('tests', 'guard')
|
15
|
+
tmux.start
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Default.start
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Terminal
|
2
|
+
class Session
|
3
|
+
attr_reader :name, :command
|
4
|
+
attr_accessor :active_window
|
5
|
+
|
6
|
+
def initialize(name = 'default', command = 'zsh')
|
7
|
+
|
8
|
+
name = 'default' if name == nil or name == ''
|
9
|
+
command = 'zsh' if command == nil or command == ''
|
10
|
+
|
11
|
+
@name = name
|
12
|
+
@command = command
|
13
|
+
@windows = []
|
14
|
+
@active_window = 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def plain
|
18
|
+
w_defs ||= build_window_string
|
19
|
+
w_opts ||= build_window_options
|
20
|
+
|
21
|
+
"new-session #{w_opts} #{command}\\;#{w_defs}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def build_window_options
|
27
|
+
"-n #{name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def build_window_string
|
32
|
+
w_str = ''
|
33
|
+
|
34
|
+
if @windows.count > 0
|
35
|
+
w_str += ' '
|
36
|
+
w_str += @windows.collect{|w| w.plain}.join(' ')
|
37
|
+
end
|
38
|
+
|
39
|
+
w_str += " select-window -t:+#{active_window}\\;"
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
public
|
44
|
+
|
45
|
+
def add_window(window)
|
46
|
+
@windows << window
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Terminal
|
2
|
+
class Window
|
3
|
+
attr_accessor :name, :command
|
4
|
+
|
5
|
+
def initialize(name = 'tab', command = 'zsh')
|
6
|
+
|
7
|
+
name = 'tab' if name == nil or name == ''
|
8
|
+
command = 'zsh' if command == nil or command == ''
|
9
|
+
|
10
|
+
@name = name
|
11
|
+
@command = command
|
12
|
+
@options = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def plain
|
16
|
+
@options.push "-n #{name}"
|
17
|
+
"new-window #{@options.join(' ')} #{command}\\;"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'terminal-multiplexer/version'
|
2
|
+
require 'terminal-multiplexer/window'
|
3
|
+
require 'terminal-multiplexer/session'
|
4
|
+
require 'terminal-multiplexer/exceptions'
|
5
|
+
|
6
|
+
require 'highline/import'
|
7
|
+
|
8
|
+
module Terminal
|
9
|
+
class Multiplexer
|
10
|
+
include Exceptions
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(*options)
|
14
|
+
# @options = {
|
15
|
+
# :default_cmd => 'zsh'
|
16
|
+
# }.update options
|
17
|
+
#
|
18
|
+
@sessions = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def new_session(name='default', command='zsh')
|
22
|
+
if @sessions.find { |s| s.name == name }
|
23
|
+
raise DuplicateSessionIdentifier , "Please do not reuse the session identifier. You used \"#{name}\" at least twice."
|
24
|
+
end
|
25
|
+
|
26
|
+
session = Session.new(name, command)
|
27
|
+
@sessions << session
|
28
|
+
session
|
29
|
+
end
|
30
|
+
|
31
|
+
def new_window(name='tab', command='zsh', session_name='default')
|
32
|
+
session = @sessions.find { |s| s.name == session_name }
|
33
|
+
|
34
|
+
|
35
|
+
if session == nil
|
36
|
+
say "Warning: No valid session found. Create a default one"
|
37
|
+
session = new_session
|
38
|
+
end
|
39
|
+
|
40
|
+
session.add_window Window.new( name , command )
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def build_multiplexer_command_string
|
47
|
+
m_str = @sessions.collect{ |s| s.plain}.join(' ')
|
48
|
+
m_str
|
49
|
+
end
|
50
|
+
|
51
|
+
public
|
52
|
+
|
53
|
+
def start(process_info={})
|
54
|
+
|
55
|
+
process_info[:cmd] = 'tmux'
|
56
|
+
process_info[:status] = system("#{process_info[:cmd]} #{build_multiplexer_command_string}")
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Terminal
|
4
|
+
describe Session do
|
5
|
+
let(:sess) { Session.new }
|
6
|
+
|
7
|
+
describe "run with rubbish options" do
|
8
|
+
let(:sess) { Session.new(nil,nil) }
|
9
|
+
|
10
|
+
it "has a name" do
|
11
|
+
sess.name.should == 'default'
|
12
|
+
end
|
13
|
+
|
14
|
+
it " has a command associated with it" do
|
15
|
+
sess.command.should == 'zsh'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "run with no option" do
|
20
|
+
|
21
|
+
it "has a name" do
|
22
|
+
sess.name.should == 'default'
|
23
|
+
end
|
24
|
+
|
25
|
+
it " has a command associated with it" do
|
26
|
+
sess.command.should == 'zsh'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "run with option" do
|
31
|
+
let(:sess) { Session.new('session','ksh') }
|
32
|
+
|
33
|
+
it "has a name" do
|
34
|
+
sess.name.should == 'session'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a command associated with it" do
|
38
|
+
sess.command.should == 'ksh'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#plain" do
|
43
|
+
it "returns the correct tmux string" do
|
44
|
+
sess.plain.should == "new-session -n default zsh\\; select-window -t:+1\\;"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#add_window" do
|
49
|
+
before :each do
|
50
|
+
@win = double('window')
|
51
|
+
@win.should_receive(:plain).and_return('new-window -n tab zsh\\;')
|
52
|
+
end
|
53
|
+
|
54
|
+
it "returns the correct tmux string" do
|
55
|
+
sess.add_window(@win)
|
56
|
+
sess.plain.should == "new-session -n default zsh\\; new-window -n tab zsh\\; select-window -t:+1\\;"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#active_window" do
|
61
|
+
it "sets the active window after creation of session and windows" do
|
62
|
+
sess.active_window(2)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Terminal
|
4
|
+
include Exceptions
|
5
|
+
|
6
|
+
describe Multiplexer do
|
7
|
+
|
8
|
+
describe "#new_session" do
|
9
|
+
let(:multi) { Multiplexer.new }
|
10
|
+
|
11
|
+
it "creates a new session with default name" do
|
12
|
+
multi.new_session
|
13
|
+
multi.send(:build_multiplexer_command_string).should == "new-session -n default zsh\\; select-window -t:+1\\;"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates a new session with given name" do
|
17
|
+
multi.new_session('session1','ksh')
|
18
|
+
multi.send(:build_multiplexer_command_string).should == "new-session -n session1 ksh\\; select-window -t:+1\\;"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "creates a string for all sessions created" do
|
22
|
+
multi.new_session
|
23
|
+
multi.new_session('session1','ksh')
|
24
|
+
multi.send(:build_multiplexer_command_string).should == "new-session -n default zsh\\; select-window -t:+1\\; new-session -n session1 ksh\\; select-window -t:+1\\;"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises an exception if a session identifier is reused" do
|
28
|
+
lambda{
|
29
|
+
multi.new_session
|
30
|
+
multi.new_session
|
31
|
+
}.should raise_error DuplicateSessionIdentifier
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#new_window" do
|
36
|
+
let(:multi) { Multiplexer.new }
|
37
|
+
|
38
|
+
it "creates a new window for the default session" do
|
39
|
+
multi.new_window
|
40
|
+
multi.send(:build_multiplexer_command_string).should == "new-session -n default zsh\\; new-window -n tab zsh\\;"
|
41
|
+
end
|
42
|
+
it "creates two session one with and one without a window if the session name doesn't match " do
|
43
|
+
multi.new_session('session1','ksh')
|
44
|
+
multi.new_window
|
45
|
+
multi.send(:build_multiplexer_command_string).should == "new-session -n session1 ksh\\; new-session -n default zsh\\; new-window -n tab zsh\\; select-window -t:+1\\;"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates two session one with and one without a window if the session name doesn't match " do
|
49
|
+
multi.new_session
|
50
|
+
multi.new_window
|
51
|
+
multi.send(:build_multiplexer_command_string).should == "new-session -n default zsh\\; new-window -n tab zsh\\; select-window -t:+1\\;"
|
52
|
+
end
|
53
|
+
|
54
|
+
#it "creates a new window for a given session" do
|
55
|
+
# multi.new_session
|
56
|
+
#end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Terminal
|
4
|
+
describe Window do
|
5
|
+
let(:win) { Window.new }
|
6
|
+
|
7
|
+
describe "run with no option" do
|
8
|
+
it "has a name" do
|
9
|
+
win.name.should == 'tab'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a command associated with it" do
|
13
|
+
win.command.should == 'zsh'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "run with option" do
|
18
|
+
let(:win) { Window.new('win','ksh') }
|
19
|
+
|
20
|
+
it "has a name" do
|
21
|
+
win.name.should == 'win'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has a command associated with it" do
|
25
|
+
win.command.should == 'ksh'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#plain" do
|
30
|
+
it "returns the correct tmux string" do
|
31
|
+
win.plain.should == "new-window -n tab zsh\\;"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "terminal-multiplexer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "terminal_multiplexer"
|
7
|
+
s.version = Terminal::VERSION
|
8
|
+
s.authors = ["Max Meyer"]
|
9
|
+
s.email = ["dev@fedux.org"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Building tmux sessions with ease}
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
# specify any dependencies here; for example:
|
19
|
+
# s.add_development_dependency "rspec"
|
20
|
+
s.add_runtime_dependency "highline"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terminal_multiplexer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Max Meyer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-04 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: highline
|
16
|
+
requirement: &13629420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *13629420
|
25
|
+
description:
|
26
|
+
email:
|
27
|
+
- dev@fedux.org
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- Guardfile
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- doc/examples/tmux_wrapper-thor.rb
|
38
|
+
- doc/examples/tmux_wrapper.rb
|
39
|
+
- env
|
40
|
+
- lib/terminal-multiplexer.rb
|
41
|
+
- lib/terminal-multiplexer/exceptions.rb
|
42
|
+
- lib/terminal-multiplexer/session.rb
|
43
|
+
- lib/terminal-multiplexer/version.rb
|
44
|
+
- lib/terminal-multiplexer/window.rb
|
45
|
+
- spec/session/session_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
- spec/terminal-multiplexer/terminal-multiplexer_spec.rb
|
48
|
+
- spec/window/window_spec.rb
|
49
|
+
- terminal_multiplexer.gemspec
|
50
|
+
homepage: ''
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.6
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Building tmux sessions with ease
|
74
|
+
test_files:
|
75
|
+
- spec/session/session_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/terminal-multiplexer/terminal-multiplexer_spec.rb
|
78
|
+
- spec/window/window_spec.rb
|