tmrb 1.2.3
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.
- data/.gitignore +7 -0
- data/Env +9 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +66 -0
- data/Guardfile +11 -0
- data/LICENCE.md +20 -0
- data/README.md +55 -0
- data/Rakefile +8 -0
- data/doc/examples/tmux_wrapper-thor.rb +21 -0
- data/doc/examples/tmux_wrapper.rb +8 -0
- data/lib/tmrb.rb +107 -0
- data/lib/tmrb/exceptions.rb +18 -0
- data/lib/tmrb/helper.rb +0 -0
- data/lib/tmrb/session.rb +75 -0
- data/lib/tmrb/version.rb +3 -0
- data/lib/tmrb/window.rb +27 -0
- data/spec/session/session_spec.rb +63 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/terminal-multiplexer/terminal-multiplexer_spec.rb +83 -0
- data/spec/window/window_spec.rb +36 -0
- data/tmrb.gemspec +20 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Env
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
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 'rake'
|
8
|
+
gem 'rspec'
|
9
|
+
gem 'guard'
|
10
|
+
gem 'guard-rspec'
|
11
|
+
gem 'pry'
|
12
|
+
gem 'libnotify'
|
13
|
+
gem 'rb-inotify'
|
14
|
+
gem 'rb-readline'
|
15
|
+
gem 'fuubar'
|
16
|
+
gem 'yard'
|
17
|
+
gem 'redcarpet'
|
18
|
+
gem 'github-markup'
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tmrb (1.2.3)
|
5
|
+
highline
|
6
|
+
thor
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.0.6)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
ffi (1.0.11)
|
14
|
+
fuubar (1.0.0)
|
15
|
+
rspec (~> 2.0)
|
16
|
+
rspec-instafail (~> 0.2.0)
|
17
|
+
ruby-progressbar (~> 0.0.10)
|
18
|
+
github-markup (0.7.2)
|
19
|
+
guard (1.0.2)
|
20
|
+
ffi (>= 0.5.0)
|
21
|
+
thor (~> 0.14.6)
|
22
|
+
guard-rspec (0.7.0)
|
23
|
+
guard (>= 0.10.0)
|
24
|
+
highline (1.6.11)
|
25
|
+
libnotify (0.7.2)
|
26
|
+
method_source (0.7.1)
|
27
|
+
pry (0.9.9.4)
|
28
|
+
coderay (~> 1.0.5)
|
29
|
+
method_source (~> 0.7.1)
|
30
|
+
slop (>= 2.4.4, < 3)
|
31
|
+
rake (0.9.2.2)
|
32
|
+
rb-inotify (0.8.8)
|
33
|
+
ffi (>= 0.5.0)
|
34
|
+
rb-readline (0.4.2)
|
35
|
+
redcarpet (2.1.1)
|
36
|
+
rspec (2.10.0)
|
37
|
+
rspec-core (~> 2.10.0)
|
38
|
+
rspec-expectations (~> 2.10.0)
|
39
|
+
rspec-mocks (~> 2.10.0)
|
40
|
+
rspec-core (2.10.0)
|
41
|
+
rspec-expectations (2.10.0)
|
42
|
+
diff-lcs (~> 1.1.3)
|
43
|
+
rspec-instafail (0.2.4)
|
44
|
+
rspec-mocks (2.10.1)
|
45
|
+
ruby-progressbar (0.0.10)
|
46
|
+
slop (2.4.4)
|
47
|
+
thor (0.14.6)
|
48
|
+
yard (0.8.1)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
fuubar
|
55
|
+
github-markup
|
56
|
+
guard
|
57
|
+
guard-rspec
|
58
|
+
libnotify
|
59
|
+
pry
|
60
|
+
rake
|
61
|
+
rb-inotify
|
62
|
+
rb-readline
|
63
|
+
redcarpet
|
64
|
+
rspec
|
65
|
+
tmrb!
|
66
|
+
yard
|
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/LICENCE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c), 2012- Max Meyer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
20
|
+
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# tmrb -- easy to use wrapper for tmux
|
2
|
+
|
3
|
+
## DESCRIPTION
|
4
|
+
|
5
|
+
`tmrb` (formerly known as terminal_multiplexer) is a wrapper for tmux to
|
6
|
+
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
|
+
The library uses semantic versioning. Please see http://semver.org for further
|
12
|
+
information.
|
13
|
+
|
14
|
+
## SYNOPSIS
|
15
|
+
|
16
|
+
```bash
|
17
|
+
#require lib
|
18
|
+
require 'terminal-multiplexer'
|
19
|
+
#create new instance
|
20
|
+
tmux = Terminal::Multiplexer.new
|
21
|
+
#create new session to hold all windows
|
22
|
+
tmux.new_session
|
23
|
+
tmux.new_session(:session_name => 'session_name' , :window_name => 'window_name', :command => 'command')
|
24
|
+
#create new window
|
25
|
+
tmux.new_window
|
26
|
+
tmux.new_window(:window_name => 'window_name', :command => 'command')
|
27
|
+
#start tmux
|
28
|
+
tmux.start
|
29
|
+
```
|
30
|
+
|
31
|
+
## INSTALL
|
32
|
+
|
33
|
+
* `Packaged:`
|
34
|
+
|
35
|
+
```bash
|
36
|
+
gem install terminal_multiplexer
|
37
|
+
```
|
38
|
+
|
39
|
+
* `Source code:`
|
40
|
+
|
41
|
+
```bash
|
42
|
+
git clone https://github.com/maxmeyer/terminal_multiplexer.git
|
43
|
+
cd terminal_multiplexer
|
44
|
+
rake build
|
45
|
+
gem install pkg/terminal_multiplexer-xxxx
|
46
|
+
```
|
47
|
+
|
48
|
+
## EXAMPLES
|
49
|
+
|
50
|
+
Please see "doc/examples/" for example scripts.
|
51
|
+
|
52
|
+
## FURTHER READING
|
53
|
+
|
54
|
+
* http://tmux.sourceforge.net
|
55
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'tmrb'
|
5
|
+
|
6
|
+
class Default < Thor
|
7
|
+
desc "work" , "Start working environment"
|
8
|
+
def work
|
9
|
+
tmux = TmRb::Multiplexer.new
|
10
|
+
tmux.new_session
|
11
|
+
tmux.new_window
|
12
|
+
tmux.new_window
|
13
|
+
tmux.new_session(:session_name=>'first session',:window_name=>'best_editor :)',:command=>'vim -p README.md')
|
14
|
+
tmux.new_window
|
15
|
+
tmux.new_window(:name => 'best shell', :command=>'zsh')
|
16
|
+
tmux.active_window(2)
|
17
|
+
tmux.start
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Default.start
|
data/lib/tmrb.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'tmrb/version'
|
2
|
+
require 'tmrb/window'
|
3
|
+
require 'tmrb/session'
|
4
|
+
require 'tmrb/exceptions'
|
5
|
+
|
6
|
+
require 'highline/import'
|
7
|
+
|
8
|
+
module TmRb
|
9
|
+
class Multiplexer
|
10
|
+
include Exceptions
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@sessions = []
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a new tmux session
|
17
|
+
#
|
18
|
+
# @param [optional,Hash] options options to create a tmux session with
|
19
|
+
# @option options [String] :session_name ('default') the name of the session itself
|
20
|
+
# @option options [String] :window_name ('tab') the name of first window of the session
|
21
|
+
# @option options [String] :command ('zsh') command which should be started in the first window of the session
|
22
|
+
# @raise [DuplicateSessionIdentifier]
|
23
|
+
def new_session(options={})
|
24
|
+
|
25
|
+
options = {
|
26
|
+
:session_name => 'default',
|
27
|
+
:window_name => 'tab',
|
28
|
+
:command => 'zsh'
|
29
|
+
}.update options
|
30
|
+
|
31
|
+
if @sessions.find { |s| s.session_name == options[:session_name] }
|
32
|
+
raise DuplicateSessionIdentifier , "Please do not reuse the session identifier. You used \"#{options[:session_name]}\" at least twice."
|
33
|
+
end
|
34
|
+
|
35
|
+
session = Session.new(options[:session_name], options[:window_name], options[:command])
|
36
|
+
@sessions << session
|
37
|
+
session
|
38
|
+
end
|
39
|
+
|
40
|
+
# Creates a new tmux window
|
41
|
+
#
|
42
|
+
# @param [optional,Hash] options options to create a tmux window with
|
43
|
+
# @option options [String] :name ('tab') the name of window
|
44
|
+
# @option options [String] :command ('zsh') command which should be started in the window
|
45
|
+
def new_window(options={})
|
46
|
+
|
47
|
+
options = {
|
48
|
+
:name => 'tab',
|
49
|
+
:command => 'zsh'
|
50
|
+
}.update options
|
51
|
+
|
52
|
+
# windows will be attached to the last session defined
|
53
|
+
session = get_last_session
|
54
|
+
|
55
|
+
#if no sessions have been created, create a new one
|
56
|
+
if session == nil
|
57
|
+
say "Warning: No valid session found. Create a default one"
|
58
|
+
session = new_session
|
59
|
+
end
|
60
|
+
|
61
|
+
#windows belong to a session
|
62
|
+
session.add_window Window.new( options[:name] , options[:command] )
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
# Set the active window in that session
|
67
|
+
#
|
68
|
+
# @param [Integer] num the number of window which should be active in that tmux session
|
69
|
+
def active_window(num)
|
70
|
+
# the active window will always be set for the last defined session
|
71
|
+
session = get_last_session
|
72
|
+
session.active_window(num)
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Get the last defined session
|
79
|
+
#
|
80
|
+
# @return [Session] last defined session
|
81
|
+
def get_last_session
|
82
|
+
@sessions[-1]
|
83
|
+
end
|
84
|
+
|
85
|
+
# Build the parameter string for all the sessions + windows
|
86
|
+
# to be used as a parameter for tmux to create that sessions and windows
|
87
|
+
#
|
88
|
+
# @return [String] whole tmux command string
|
89
|
+
def build_multiplexer_command_string
|
90
|
+
m_str = @sessions.collect{ |s| s.to_string}.join(' ')
|
91
|
+
m_str
|
92
|
+
end
|
93
|
+
|
94
|
+
public
|
95
|
+
|
96
|
+
# Start tmux
|
97
|
+
#
|
98
|
+
# @param [optional,Hash] process_info a hash containing information about the tmux process to be started
|
99
|
+
def start(process_info={})
|
100
|
+
|
101
|
+
process_info[:cmd] = 'tmux'
|
102
|
+
process_info[:status] = system(%Q{#{process_info[:cmd]} #{build_multiplexer_command_string} attach})
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module TmRb
|
2
|
+
module Exceptions
|
3
|
+
|
4
|
+
# Exception which should be raised
|
5
|
+
# if no session is found which can be used
|
6
|
+
# for that particular command
|
7
|
+
#
|
8
|
+
class SessionNotFound < Exception
|
9
|
+
end
|
10
|
+
|
11
|
+
# If you create a session you could choose an identifier
|
12
|
+
# on your own. Every Session has to have its own
|
13
|
+
# unique session identifier.
|
14
|
+
class DuplicateSessionIdentifier < Exception
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/tmrb/helper.rb
ADDED
File without changes
|
data/lib/tmrb/session.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
module Terminal
|
2
|
+
class Session
|
3
|
+
attr_reader :session_name, :window_name, :command
|
4
|
+
|
5
|
+
# Create the session
|
6
|
+
#
|
7
|
+
# @param [String] session_name the name of the session
|
8
|
+
# @param [String] window_name the name of the first window of the session
|
9
|
+
# @param [String] command the command which should be executed in the first window of the session
|
10
|
+
def initialize(session_name, window_name, command)
|
11
|
+
|
12
|
+
@session_name = session_name
|
13
|
+
@window_name = window_name
|
14
|
+
@command = command
|
15
|
+
@windows = []
|
16
|
+
@active_window = 1
|
17
|
+
end
|
18
|
+
|
19
|
+
# Set the active window in that session
|
20
|
+
#
|
21
|
+
# @param [Integer] num the number of the active window of that session
|
22
|
+
# @return [Integer] the number of the active window
|
23
|
+
def active_window(num)
|
24
|
+
@active_window=num
|
25
|
+
end
|
26
|
+
|
27
|
+
# Build the whole session string for tmux
|
28
|
+
#
|
29
|
+
# @return [String] tmux session
|
30
|
+
def to_string
|
31
|
+
w_defs ||= build_window_string
|
32
|
+
s_opts ||= build_session_options
|
33
|
+
|
34
|
+
%Q{new-session #{s_opts} "#{command}"\\;#{w_defs}}
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# Build the session options
|
40
|
+
#
|
41
|
+
# @return [String] tmux session options
|
42
|
+
def build_session_options
|
43
|
+
%Q{-s "#{session_name}" -n "#{window_name}"}
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Build the string containing all created windows
|
48
|
+
#
|
49
|
+
# @return [String] tmux window declartions
|
50
|
+
def build_window_string
|
51
|
+
w_str = ''
|
52
|
+
|
53
|
+
#strings for the windows
|
54
|
+
if @windows.count > 0
|
55
|
+
w_str += ' '
|
56
|
+
w_str += @windows.collect{|w| w.to_string}.join(' ')
|
57
|
+
end
|
58
|
+
|
59
|
+
#string for the selected window in that session
|
60
|
+
w_str += " select-window -t:+#{@active_window}\\;"
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
public
|
65
|
+
|
66
|
+
# Add a window to the session
|
67
|
+
#
|
68
|
+
# @param [Window] window the object containing the window which should be added to the session
|
69
|
+
# @return [Window] the object itself
|
70
|
+
def add_window(window)
|
71
|
+
@windows << window
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/lib/tmrb/version.rb
ADDED
data/lib/tmrb/window.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module TmRb
|
2
|
+
class Window
|
3
|
+
attr_accessor :name, :command
|
4
|
+
|
5
|
+
# Create a tmux window
|
6
|
+
#
|
7
|
+
# @param [String] name the name of the window
|
8
|
+
# @param [String] command the command executed in the window
|
9
|
+
def initialize(name = 'tab', command = 'zsh')
|
10
|
+
|
11
|
+
name = 'tab' if name == nil or name == ''
|
12
|
+
command = 'zsh' if command == nil or command == ''
|
13
|
+
|
14
|
+
@name = name
|
15
|
+
@command = command
|
16
|
+
@options = []
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return the tmux string for the window
|
20
|
+
#
|
21
|
+
# @return [String] window declaration
|
22
|
+
def to_string
|
23
|
+
@options.push %Q{-n "#{name}"}
|
24
|
+
%Q{new-window #{@options.join(' ')} "#{command}"\\;}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Terminal
|
4
|
+
describe Session do
|
5
|
+
let(:sess) { Session.new('default','tab','zsh') }
|
6
|
+
|
7
|
+
describe "run with rubbish options" do
|
8
|
+
let(:sess) { Session.new(nil,nil,nil) }
|
9
|
+
|
10
|
+
it "has a session name" do
|
11
|
+
sess.session_name.should == nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a window name" do
|
15
|
+
sess.window_name.should == nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has a command associated with it" do
|
19
|
+
sess.command.should == nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "run with option" do
|
24
|
+
let(:sess) { Session.new('session','tab','ksh') }
|
25
|
+
|
26
|
+
it "has a session name" do
|
27
|
+
sess.session_name.should == 'session'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has a window name" do
|
31
|
+
sess.window_name.should == 'tab'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has a command associated with it" do
|
35
|
+
sess.command.should == 'ksh'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#to_string" do
|
40
|
+
it "returns the correct tmux string" do
|
41
|
+
sess.to_string.should == %Q{new-session -s "default" -n "tab" "zsh"\\; select-window -t:+1\\;}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#add_window" do
|
46
|
+
before :each do
|
47
|
+
@win = double('window')
|
48
|
+
@win.should_receive(:to_string).and_return('new-window -n "tab" "zsh"\\;')
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns the correct tmux string" do
|
52
|
+
sess.add_window(@win)
|
53
|
+
sess.to_string.should == %q{new-session -s "default" -n "tab" "zsh"\\; new-window -n "tab" "zsh"\\; select-window -t:+1\\;}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#active_window" do
|
58
|
+
it "sets the active window after creation of session and windows" do
|
59
|
+
sess.active_window(2)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Terminal
|
4
|
+
include Exceptions
|
5
|
+
|
6
|
+
describe Multiplexer do
|
7
|
+
|
8
|
+
let(:multi) { Multiplexer.new }
|
9
|
+
|
10
|
+
describe "#new_session" do
|
11
|
+
|
12
|
+
it "creates a new session with default name" do
|
13
|
+
multi.new_session
|
14
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "default" -n "tab" "zsh"\\; select-window -t:+1\\;}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "creates a new session with given name" do
|
18
|
+
multi.new_session(:session_name => 'session1', :window_name => 'tab', :command => 'ksh')
|
19
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "session1" -n "tab" "ksh"\\; select-window -t:+1\\;}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "creates a string for all sessions created" do
|
23
|
+
multi.new_session
|
24
|
+
multi.new_session(:session_name => 'session1', :window_name => 'tab', :command => 'ksh')
|
25
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "default" -n "tab" "zsh"\\; select-window -t:+1\\; new-session -s "session1" -n "tab" "ksh"\\; select-window -t:+1\\;}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "raises an exception if a session identifier is reused" do
|
29
|
+
lambda{
|
30
|
+
multi.new_session
|
31
|
+
multi.new_session
|
32
|
+
}.should raise_error DuplicateSessionIdentifier
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#new_window" do
|
37
|
+
it "creates a new window for the default session" do
|
38
|
+
multi.new_window
|
39
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "default" -n "tab" "zsh"\\; new-window -n "tab" "zsh"\\; select-window -t:+1\\;}
|
40
|
+
end
|
41
|
+
it "creates a new window for \"session1\"" do
|
42
|
+
multi.new_session(:session_name => 'session1', :window_name => 'tab', :command => 'ksh')
|
43
|
+
multi.new_window
|
44
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "session1" -n "tab" "ksh"\\; new-window -n "tab" "zsh"\\; select-window -t:+1\\;}
|
45
|
+
end
|
46
|
+
|
47
|
+
it "creates a new window for session \"default\"" do
|
48
|
+
multi.new_session
|
49
|
+
multi.new_window
|
50
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "default" -n "tab" "zsh"\\; new-window -n "tab" "zsh"\\; select-window -t:+1\\;}
|
51
|
+
end
|
52
|
+
|
53
|
+
it "creates 2 windows in session1 and 2 windows in session2 (the last defined session, after creating the windows)" do
|
54
|
+
multi.new_session(:session_name => 'session1', :window_name => 'tab', :command => 'ksh')
|
55
|
+
multi.new_window(:name => 'window1', :command => 'ksh')
|
56
|
+
multi.new_window(:name => 'window2', :command => 'ksh')
|
57
|
+
multi.new_session(:session_name => 'session2', :window_name => 'tab', :command => 'ksh')
|
58
|
+
multi.new_window(:name => 'window3', :command => 'ksh')
|
59
|
+
multi.new_window(:name => 'window4', :command => 'ksh')
|
60
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "session1" -n "tab" "ksh"\\; new-window -n "window1" "ksh"\\; new-window -n "window2" "ksh"\\; select-window -t:+1\\; new-session -s "session2" -n "tab" "ksh"\\; new-window -n "window3" "ksh"\\; new-window -n "window4" "ksh"\\; select-window -t:+1\\;}
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#active_window" do
|
66
|
+
it "selects the window from the last defined session" do
|
67
|
+
multi.new_session(:session_name => 'session1', :window_name => 'tab', :command => 'ksh')
|
68
|
+
multi.new_window(:name => 'window1', :command => 'ksh')
|
69
|
+
multi.new_window(:name => 'window2', :command => 'ksh')
|
70
|
+
multi.active_window(2)
|
71
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "session1" -n "tab" "ksh"\\; new-window -n "window1" "ksh"\\; new-window -n "window2" "ksh"\\; select-window -t:+2\\;}
|
72
|
+
end
|
73
|
+
|
74
|
+
it "doesn't matter where you place the window selector. It selects the window from the last defined session" do
|
75
|
+
multi.new_session(:session_name => 'session1', :window_name => 'tab', :command => 'ksh')
|
76
|
+
multi.active_window(2)
|
77
|
+
multi.new_window(:name => 'window1', :command => 'ksh')
|
78
|
+
multi.new_window(:name => 'window2', :command => 'ksh')
|
79
|
+
multi.send(:build_multiplexer_command_string).should == %Q{new-session -s "session1" -n "tab" "ksh"\\; new-window -n "window1" "ksh"\\; new-window -n "window2" "ksh"\\; select-window -t:+2\\;}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
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 "#to_string" do
|
30
|
+
it "returns the correct tmux string" do
|
31
|
+
win.to_string.should == %Q{new-window -n "tab" "zsh"\\;}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/tmrb.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH << File.expand_path("../lib", __FILE__)
|
3
|
+
require 'tmrb/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tmrb"
|
7
|
+
s.version = TmRb::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
|
+
s.add_runtime_dependency "highline"
|
19
|
+
s.add_runtime_dependency "thor"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tmrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Max Meyer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-09 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: highline
|
17
|
+
requirement: &12431960 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *12431960
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: thor
|
28
|
+
requirement: &12431280 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *12431280
|
37
|
+
description:
|
38
|
+
email:
|
39
|
+
- dev@fedux.org
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Env
|
46
|
+
- Gemfile
|
47
|
+
- Gemfile.lock
|
48
|
+
- Guardfile
|
49
|
+
- LICENCE.md
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- doc/examples/tmux_wrapper-thor.rb
|
53
|
+
- doc/examples/tmux_wrapper.rb
|
54
|
+
- lib/tmrb.rb
|
55
|
+
- lib/tmrb/exceptions.rb
|
56
|
+
- lib/tmrb/helper.rb
|
57
|
+
- lib/tmrb/session.rb
|
58
|
+
- lib/tmrb/version.rb
|
59
|
+
- lib/tmrb/window.rb
|
60
|
+
- spec/session/session_spec.rb
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/terminal-multiplexer/terminal-multiplexer_spec.rb
|
63
|
+
- spec/window/window_spec.rb
|
64
|
+
- tmrb.gemspec
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: ''
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.6.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Building tmux sessions with ease
|
90
|
+
test_files:
|
91
|
+
- spec/session/session_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/terminal-multiplexer/terminal-multiplexer_spec.rb
|
94
|
+
- spec/window/window_spec.rb
|