lab42_tmux2 0.0.1pre3 → 0.0.1pre4
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.
- checksums.yaml +4 -4
- data/README.md +25 -3
- data/lib/lab42/tmux/config.rb +3 -0
- data/lib/lab42/tmux/dry_run.rb +18 -1
- data/lib/lab42/tmux/session/commands.rb +36 -6
- data/lib/lab42/tmux/session/parameter_helpers.rb +2 -2
- data/lib/lab42/tmux/session.rb +20 -26
- data/lib/lab42/tmux/version.rb +1 -1
- data/lib/lab42/tmux.rb +1 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d83b9c45369edab02ddee3ff9248a899dfd5f89d
|
4
|
+
data.tar.gz: 737d9d882cb972d5de3d87e6e6fd6823fe98aac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7023719f39716a788a03e60c3ca1fd632c453bbbbca3d5a911cebb492918166eb33af6b9a1f8e62078d23dfad5eac0fab9aa52ad191e1fab8abcbab80172de16
|
7
|
+
data.tar.gz: 9ef8c13b005882f231dba5a49a624e0d4b725b6a15a7fa8ca0cf20537453302a85db132db42413addb67b245f0bc5fc6f3611058979271f056084a6beb3ade69
|
data/README.md
CHANGED
@@ -25,12 +25,12 @@ A simple API for launching tmux sessions from Ruby scripts
|
|
25
25
|
|
26
26
|
session "vi_session" do
|
27
27
|
configure do | c |
|
28
|
-
c.home '.'
|
29
|
-
c.
|
28
|
+
c.home '.' # Would have been the default
|
29
|
+
c.window_automatic_rename true # Default is false
|
30
30
|
end
|
31
31
|
new_window 'vi' do
|
32
32
|
send_keys 'vi .'
|
33
|
-
wait_for '.. (up a dir)'
|
33
|
+
wait_for '.. (up a dir)' # NERDTree pane has loaded (not yet implemented)
|
34
34
|
send_keys_raw 'C-w', 'l'
|
35
35
|
end
|
36
36
|
new_window 'pry' do
|
@@ -40,6 +40,28 @@ A simple API for launching tmux sessions from Ruby scripts
|
|
40
40
|
end
|
41
41
|
```
|
42
42
|
|
43
|
+
### Hooks
|
44
|
+
|
45
|
+
Add a `after_new_window` hook for tmux commands to be executed after the creation of a new
|
46
|
+
window.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
session 'my rails' do
|
50
|
+
after_new_window do
|
51
|
+
send_keys "rvm use default@my-rails"
|
52
|
+
end
|
53
|
+
# ...
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
### Plugins
|
59
|
+
|
60
|
+
Plugins are easy to write, just MP the `Lab42::Tmux::Session` class. However precise guidelines
|
61
|
+
how to do this will be available soon, also you might want to create some configuration.
|
62
|
+
|
63
|
+
The plugin guidelines and some plugins (vi, ruby, rvm, python's virtualenv) are planned for
|
64
|
+
the near future.
|
43
65
|
|
44
66
|
## Dev Notes
|
45
67
|
|
data/lib/lab42/tmux/config.rb
CHANGED
@@ -15,10 +15,13 @@ module Lab42
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
define_setter_getters :pre_wait_interval, :post_wait_interval, :wait_interval, :wait_timeout
|
18
19
|
define_setter_getters :session_name, :window_automatic_rename
|
19
20
|
|
20
21
|
private
|
21
22
|
def initialize
|
23
|
+
@wait_interval = 0.5
|
24
|
+
@wait_timeout = 2
|
22
25
|
end
|
23
26
|
end # module Config
|
24
27
|
end # module Tmux
|
data/lib/lab42/tmux/dry_run.rb
CHANGED
@@ -7,7 +7,24 @@ module Lab42
|
|
7
7
|
end
|
8
8
|
def query *args
|
9
9
|
puts args.join( ' ' )
|
10
|
-
|
10
|
+
if args.first == 'capture-pane'
|
11
|
+
capture_pane( *args.drop( 1 ) )
|
12
|
+
else
|
13
|
+
args.first != 'has-session'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def capture_pane *args
|
19
|
+
pane_addr = args[1]
|
20
|
+
second_capture = (@panes ||= {})[pane_addr]
|
21
|
+
if second_capture
|
22
|
+
@panes[pane_addr] = false
|
23
|
+
'hit'
|
24
|
+
else
|
25
|
+
@panes[pane_addr] = true
|
26
|
+
'miss'
|
27
|
+
end
|
11
28
|
end
|
12
29
|
end # module Interface
|
13
30
|
end # module Tmux
|
@@ -4,17 +4,47 @@ module Lab42
|
|
4
4
|
module Tmux
|
5
5
|
class Session
|
6
6
|
module Commands
|
7
|
-
def new_window
|
8
|
-
@
|
9
|
-
|
7
|
+
def new_window window_name, &block
|
8
|
+
@window_number += 1
|
9
|
+
command 'new-window', '-t', session_name, '-n', window_name
|
10
10
|
instance_exec( &@after_new_window_hook ) if @after_new_window_hook
|
11
|
-
|
11
|
+
instance_exec( &block ) if block
|
12
12
|
end
|
13
13
|
|
14
14
|
def send_keys *keys
|
15
|
-
|
16
|
-
commands << %W{ send-keys #{window_address} #{keys.map(&:inspect).join(' ')} C-m }
|
15
|
+
command( 'send-keys', '-t', [session_name, window_number].join(':'), *keys.map(&:inspect), 'C-m' )
|
17
16
|
end
|
17
|
+
|
18
|
+
def wait_for text_or_rgx, alternate_pane_addr=nil, &blk
|
19
|
+
require 'timeout'
|
20
|
+
pane_addr = alternate_pane_addr || window_address
|
21
|
+
text_or_rgx = %r{#{text_or_rgx}} unless Regexp === text_or_rgx
|
22
|
+
conditional_sleep configuration.pre_wait_interval
|
23
|
+
Timeout.timeout configuration.wait_timeout do
|
24
|
+
really_wait_for text_or_rgx, in_pane: pane_addr, dependent_actions: blk
|
25
|
+
end
|
26
|
+
rescue Timeout::Error
|
27
|
+
end
|
28
|
+
|
29
|
+
def really_wait_for( match_rgx, in_pane:, dependent_actions: )
|
30
|
+
loop do
|
31
|
+
text = capture_pane in_pane
|
32
|
+
if match_rgx === text
|
33
|
+
conditional_sleep configuration.post_wait_interval
|
34
|
+
return instance_exec( &dependent_actions )
|
35
|
+
end
|
36
|
+
sleep configuration.wait_interval
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def capture_pane pane_addr
|
42
|
+
query( 'capture-pane', *(pane_addr.split), '-p' )
|
43
|
+
end
|
44
|
+
def conditional_sleep sleepy_or_falsy
|
45
|
+
sleep sleepy_or_falsy if sleepy_or_falsy
|
46
|
+
end
|
47
|
+
|
18
48
|
end # module Commands
|
19
49
|
include Commands
|
20
50
|
end # class Session
|
@@ -3,10 +3,10 @@ module Lab42
|
|
3
3
|
class Session
|
4
4
|
module ParameterHelpers
|
5
5
|
def session_address
|
6
|
-
"-t #{
|
6
|
+
"-t #{session_name}"
|
7
7
|
end
|
8
8
|
def window_address
|
9
|
-
"-t #{
|
9
|
+
"-t #{session_name}:#{window_number}"
|
10
10
|
end
|
11
11
|
end # module ParameterHelpers
|
12
12
|
include ParameterHelpers
|
data/lib/lab42/tmux/session.rb
CHANGED
@@ -2,36 +2,33 @@ require_relative 'errors'
|
|
2
2
|
require_relative 'session/commands'
|
3
3
|
require_relative 'session/hooks'
|
4
4
|
|
5
|
+
require 'forwarder'
|
6
|
+
|
5
7
|
module Lab42
|
6
8
|
module Tmux
|
7
9
|
class Session
|
8
|
-
|
10
|
+
|
11
|
+
attr_reader :commands, :configuration, :session_name, :window_number
|
12
|
+
|
13
|
+
extend Forwarder
|
14
|
+
forward_all :command, :query, to_object: Interface
|
9
15
|
|
10
16
|
def config &block
|
11
17
|
block.( configuration )
|
12
18
|
end
|
13
19
|
|
14
|
-
def
|
15
|
-
@definition_block = block
|
16
|
-
end
|
17
|
-
|
18
|
-
def run
|
19
|
-
register_commands
|
20
|
-
run_registered_commands
|
21
|
-
end
|
22
|
-
|
23
|
-
def register_commands
|
20
|
+
def run &block
|
24
21
|
return attach if running?
|
25
|
-
|
26
|
-
|
27
|
-
instance_exec( &@definition_block ) if @definition_block
|
22
|
+
create_session
|
23
|
+
instance_exec( &block )
|
28
24
|
attach
|
29
25
|
end
|
30
26
|
|
27
|
+
|
31
28
|
private
|
32
29
|
def initialize sess_name
|
33
|
-
@
|
34
|
-
@
|
30
|
+
@session_name = sess_name
|
31
|
+
@window_number = 0
|
35
32
|
@commands = []
|
36
33
|
@configuration = Config.new
|
37
34
|
|
@@ -39,21 +36,18 @@ module Lab42
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def attach
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_command *args
|
46
|
-
commands << args
|
39
|
+
command 'attach-session', '-t', session_name
|
47
40
|
end
|
48
41
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
def create_session
|
43
|
+
command 'source-file', File.join( ENV["HOME"], '.tmux.conf' )
|
44
|
+
# TODO: replace 'sh' with a configuration value
|
45
|
+
command 'new-session', '-d', '-s', session_name, '-n', 'sh'
|
46
|
+
command 'set-window-option', '-g', 'automatic-rename', 'off' unless configuration.window_automatic_rename
|
53
47
|
end
|
54
48
|
|
55
49
|
def running?
|
56
|
-
Interface.query 'has-session', '-t',
|
50
|
+
Interface.query 'has-session', '-t', session_name
|
57
51
|
end
|
58
52
|
|
59
53
|
def run_command command
|
data/lib/lab42/tmux/version.rb
CHANGED
data/lib/lab42/tmux.rb
CHANGED
@@ -8,8 +8,7 @@ module Lab42
|
|
8
8
|
def new_session session_name=nil, &block
|
9
9
|
raise ArgumentError, 'No block provided' unless block
|
10
10
|
session = Session.new session_name || Config.session_name
|
11
|
-
session.
|
12
|
-
session.run
|
11
|
+
session.run &block
|
13
12
|
end
|
14
13
|
|
15
14
|
def dry_run!
|
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.1pre4
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwarder2
|