lab42_tmux2 0.0.1pre2 → 0.0.1pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/lab42/tmux/auto_import.rb +1 -0
- data/lib/lab42/tmux/config.rb +18 -5
- data/lib/lab42/tmux/dry_run.rb +14 -0
- data/lib/lab42/tmux/errors.rb +1 -0
- data/lib/lab42/tmux/interface.rb +0 -1
- data/lib/lab42/tmux/session/commands.rb +3 -0
- data/lib/lab42/tmux/session/hooks.rb +19 -0
- data/lib/lab42/tmux/session.rb +15 -5
- data/lib/lab42/tmux/version.rb +1 -1
- data/lib/lab42/tmux.rb +5 -6
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 011cc804cf724cd9516c46971d0d21b60f333a0c
|
4
|
+
data.tar.gz: 3a33a65919f51e7f885abdf714583ed55f90f18b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cab3d6012d10a33dae63ddfae8df3b5c0d1ad8738e2e92d0b8d681ec7a9ad97c76e3b64282b8af4aa9a1689dcbb68ab9e30193372cf732c2cf1d51e5bc761fdf
|
7
|
+
data.tar.gz: 302912baf4d282e8345e28747f4c90fd3d2a55a6d8c056f33e43c8ddfdd2427ee97a21a265044bbb0dc618f0e8d4d0c5c01a04c186565bb81afe13b953c5e0ce
|
data/README.md
CHANGED
@@ -23,12 +23,11 @@ A simple API for launching tmux sessions from Ruby scripts
|
|
23
23
|
```ruby
|
24
24
|
require 'lab42/tmux/autoimport'
|
25
25
|
|
26
|
-
configure do | c |
|
27
|
-
c.home '.' # Would have been the default
|
28
|
-
c.session_name = ARGV.first # Would have been the default
|
29
|
-
end
|
30
|
-
|
31
26
|
session "vi_session" do
|
27
|
+
configure do | c |
|
28
|
+
c.home '.' # Would have been the default
|
29
|
+
c.session_name = ARGV.first # Would have been the default
|
30
|
+
end
|
32
31
|
new_window 'vi' do
|
33
32
|
send_keys 'vi .'
|
34
33
|
wait_for '.. (up a dir)' # NERDTree pane has loaded
|
data/lib/lab42/tmux/config.rb
CHANGED
@@ -1,11 +1,24 @@
|
|
1
1
|
module Lab42
|
2
2
|
module Tmux
|
3
|
-
|
4
|
-
|
3
|
+
class Config
|
4
|
+
|
5
|
+
def self.define_setter_getter name
|
6
|
+
define_method name do |*args|
|
7
|
+
return instance_variable_get("@#{name}") if args.empty?
|
8
|
+
instance_variable_set "@#{name}", args.first
|
9
|
+
end
|
5
10
|
end
|
6
|
-
|
7
|
-
|
8
|
-
|
11
|
+
|
12
|
+
def self.define_setter_getters *names
|
13
|
+
names.each do | name |
|
14
|
+
define_setter_getter( name )
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
define_setter_getters :session_name, :window_automatic_rename
|
19
|
+
|
20
|
+
private
|
21
|
+
def initialize
|
9
22
|
end
|
10
23
|
end # module Config
|
11
24
|
end # module Tmux
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lab42
|
2
|
+
module Tmux
|
3
|
+
# Dry Run Interface
|
4
|
+
module Interface extend self
|
5
|
+
def command *args
|
6
|
+
puts args.join( ' ' )
|
7
|
+
end
|
8
|
+
def query *args
|
9
|
+
puts args.join( ' ' )
|
10
|
+
return args.first != 'has-session'
|
11
|
+
end
|
12
|
+
end # module Interface
|
13
|
+
end # module Tmux
|
14
|
+
end # module Lab42
|
data/lib/lab42/tmux/errors.rb
CHANGED
data/lib/lab42/tmux/interface.rb
CHANGED
@@ -7,9 +7,12 @@ module Lab42
|
|
7
7
|
def new_window name
|
8
8
|
@win_number += 1
|
9
9
|
commands << %W{ new-window #{session_address} -n #{name} }
|
10
|
+
instance_exec( &@after_new_window_hook ) if @after_new_window_hook
|
11
|
+
# TODO: Include after_new_window hoox
|
10
12
|
end
|
11
13
|
|
12
14
|
def send_keys *keys
|
15
|
+
# TODO: determine target of the << operation (if in hook we need something more complicated here)
|
13
16
|
commands << %W{ send-keys #{window_address} #{keys.map(&:inspect).join(' ')} C-m }
|
14
17
|
end
|
15
18
|
end # module Commands
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative '../errors'
|
2
|
+
|
3
|
+
module Lab42
|
4
|
+
module Tmux
|
5
|
+
class Session
|
6
|
+
module Hooks
|
7
|
+
def after_new_window &blk
|
8
|
+
raise ArgumentError, 'after_new_window needs a block' unless blk
|
9
|
+
raise MultipleHook, 'no multiple after_new_window hooks allowed in one session' if @after_new_window_hook
|
10
|
+
|
11
|
+
@after_new_window_hook = blk
|
12
|
+
# **This one is **ugly**, for implicit window 0
|
13
|
+
instance_exec(&blk)
|
14
|
+
end
|
15
|
+
end # module Hooks
|
16
|
+
include Hooks
|
17
|
+
end # class Session
|
18
|
+
end # module Tmux
|
19
|
+
end # module Lab42
|
data/lib/lab42/tmux/session.rb
CHANGED
@@ -1,22 +1,29 @@
|
|
1
1
|
require_relative 'errors'
|
2
2
|
require_relative 'session/commands'
|
3
|
+
require_relative 'session/hooks'
|
3
4
|
|
4
5
|
module Lab42
|
5
6
|
module Tmux
|
6
7
|
class Session
|
7
|
-
attr_reader :commands, :name, :win_number
|
8
|
+
attr_reader :commands, :configuration, :name, :win_number
|
8
9
|
|
10
|
+
def config &block
|
11
|
+
block.( configuration )
|
12
|
+
end
|
13
|
+
|
9
14
|
def define block
|
10
15
|
@definition_block = block
|
11
16
|
end
|
12
17
|
|
13
|
-
def run
|
14
|
-
|
18
|
+
def run
|
19
|
+
register_commands
|
15
20
|
run_registered_commands
|
16
21
|
end
|
17
22
|
|
18
|
-
def
|
19
|
-
|
23
|
+
def register_commands
|
24
|
+
return attach if running?
|
25
|
+
|
26
|
+
create_session_and_windows
|
20
27
|
instance_exec( &@definition_block ) if @definition_block
|
21
28
|
attach
|
22
29
|
end
|
@@ -26,6 +33,7 @@ module Lab42
|
|
26
33
|
@name = sess_name
|
27
34
|
@win_number = 0
|
28
35
|
@commands = []
|
36
|
+
@configuration = Config.new
|
29
37
|
|
30
38
|
self.class.instance self
|
31
39
|
end
|
@@ -37,9 +45,11 @@ module Lab42
|
|
37
45
|
def add_command *args
|
38
46
|
commands << args
|
39
47
|
end
|
48
|
+
|
40
49
|
def create_session_and_windows
|
41
50
|
add_command 'source-file', File.join( ENV["HOME"], '.tmux.conf' )
|
42
51
|
add_command 'new-session', '-d', '-s', name, '-n', 'sh'
|
52
|
+
add_command 'set-window-option', '-g', 'automatic-rename', 'off' unless configuration.window_automatic_rename
|
43
53
|
end
|
44
54
|
|
45
55
|
def running?
|
data/lib/lab42/tmux/version.rb
CHANGED
data/lib/lab42/tmux.rb
CHANGED
@@ -9,12 +9,11 @@ module Lab42
|
|
9
9
|
raise ArgumentError, 'No block provided' unless block
|
10
10
|
session = Session.new session_name || Config.session_name
|
11
11
|
session.define block if block
|
12
|
-
session.run
|
12
|
+
session.run
|
13
|
+
end
|
14
|
+
|
15
|
+
def dry_run!
|
16
|
+
require_relative 'tmux/dry_run'
|
13
17
|
end
|
14
|
-
|
15
18
|
end # module Tmux
|
16
19
|
end # module Lab42
|
17
|
-
|
18
|
-
at_exit do
|
19
|
-
Lab42::Tmux::Session.run
|
20
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_tmux2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwarder2
|
@@ -77,10 +77,12 @@ files:
|
|
77
77
|
- lib/lab42/tmux.rb
|
78
78
|
- lib/lab42/tmux/auto_import.rb
|
79
79
|
- lib/lab42/tmux/config.rb
|
80
|
+
- lib/lab42/tmux/dry_run.rb
|
80
81
|
- lib/lab42/tmux/errors.rb
|
81
82
|
- lib/lab42/tmux/interface.rb
|
82
83
|
- lib/lab42/tmux/session.rb
|
83
84
|
- lib/lab42/tmux/session/commands.rb
|
85
|
+
- lib/lab42/tmux/session/hooks.rb
|
84
86
|
- lib/lab42/tmux/session/parameter_helpers.rb
|
85
87
|
- lib/lab42/tmux/version.rb
|
86
88
|
homepage: https://github.com/RobertDober/lab42_tmux
|