lab42_tmux2 0.0.1pre2 → 0.0.1pre3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ff5a4e128bce5e7dabd4588da56010c2f3544ab
4
- data.tar.gz: 960fa2f5ea0197610f316606a53bbccb714b4b23
3
+ metadata.gz: 011cc804cf724cd9516c46971d0d21b60f333a0c
4
+ data.tar.gz: 3a33a65919f51e7f885abdf714583ed55f90f18b
5
5
  SHA512:
6
- metadata.gz: 9f54f31a41d331d2a8283277d702064f25a493977f289ce349ea98cb4b548457d3c033c7dc89c83d02cd56ac45add87c55040a191cd8b69a1a9094347dabd5a8
7
- data.tar.gz: 6d14ccdc3f048c09ff090371123bd11d4b159fefb74e6554d2973816bf9bf0e81d99d1823c0b138e7a373e38a9f0344e68cd9b02d87117f30bbd821566a2b9c9
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
@@ -1,3 +1,4 @@
1
1
  require_relative '../tmux'
2
2
 
3
3
  T = Tmux = Lab42::Tmux
4
+ include T
@@ -1,11 +1,24 @@
1
1
  module Lab42
2
2
  module Tmux
3
- module Config extend self
4
- def init_singleton
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
- def session_name *args
7
- return @session_name if args.empty?
8
- @session_name = args.first
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
@@ -1,5 +1,6 @@
1
1
  module Lab42
2
2
  module Tmux
3
3
  NoSessionDefined = Class.new RuntimeError
4
+ MultipleHook = Class.new RuntimeError
4
5
  end # module Tmux
5
6
  end # module Lab42
@@ -2,7 +2,6 @@ module Lab42
2
2
  module Tmux
3
3
  module Interface extend self
4
4
  def command *args
5
- p args
6
5
  %x{ tmux #{ args.join ' ' } }
7
6
  end
8
7
  def query *args
@@ -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
@@ -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
- run
18
+ def run
19
+ register_commands
15
20
  run_registered_commands
16
21
  end
17
22
 
18
- def run
19
- create_session_and_windows unless running?
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?
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Lab42
3
3
  module Tmux
4
- VERSION = '0.0.1pre2'
4
+ VERSION = '0.0.1pre3'
5
5
  end # module Tmux
6
6
  end # module Lab42
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.1pre2
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 00:00:00.000000000 Z
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