lab42_tmux2 0.0.1pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27dcb543997e44fb1260fce8c062329b594f4007
4
+ data.tar.gz: 67c341a73e88287d967e53e52a2321201cad14f0
5
+ SHA512:
6
+ metadata.gz: 0b4abd3b83885ac423ee7116a3090935f4a5cbba60ba0ceaf9b8d04e5ac7f5b45b460e992c878c1e538b3c73125f0128f9d228902569fccc9e293307f6d0cbd0
7
+ data.tar.gz: cd9e6348722f7806a405e42659b7a22f980d136a73d3da9f2b31d8075fc7eac78be5f15de4421ffcbbdf6f76a9ce970ce982897ceb37235db7b1674554046f80
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Robert Dober
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+
2
+ # Lab42, Programmers' Best Friend In Ruby 2
3
+
4
+ ## Tmux2
5
+
6
+ **N.B.** This is a complete rewrite of tmux and it is **not** compatible, IOW do not
7
+ install both gems.
8
+
9
+ These are the differences
10
+
11
+ * Everything has changed.
12
+
13
+ * Furthermore, nothing has remained the same
14
+
15
+ * There are no predefined scripts, but have a look at the examples.
16
+
17
+ ## Purpose
18
+
19
+ A simple API for launching tmux sessions from Ruby scripts
20
+
21
+ ### A simple example
22
+
23
+ ```ruby
24
+ require 'lab42/tmux/autoimport'
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
+ session "vi_session" do
32
+ new_window 'vi' do
33
+ send_keys 'vi .'
34
+ wait_for '.. (up a dir)' # NERDTree pane has loaded
35
+ send_keys_raw 'C-w', 'l'
36
+ end
37
+ new_window 'pry' do
38
+ send_keys 'pry -Ilib'
39
+ send_keys 'require "lab42/tmux"'
40
+ end
41
+ end
42
+ ```
43
+
44
+
45
+ ## Dev Notes
46
+
47
+ ### Acceptance Tests
48
+
49
+ For each example script there is a corresponding expecatation output in the
50
+ `expectations` directory. Use the acceptance_tests script to run the examples
51
+ and compare the output with the expectations.
52
+
53
+
54
+ The expectation files are primitive and need some simple adaptations to your environment, hopefully
55
+ that will change.
@@ -0,0 +1,3 @@
1
+ require_relative '../tmux'
2
+
3
+ T = Tmux = Lab42::Tmux
@@ -0,0 +1,12 @@
1
+ module Lab42
2
+ module Tmux
3
+ module Config extend self
4
+ def init_singleton
5
+ end
6
+ def session_name *args
7
+ return @session_name if args.empty?
8
+ @session_name = args.first
9
+ end
10
+ end # module Config
11
+ end # module Tmux
12
+ end # module Lab42
@@ -0,0 +1,5 @@
1
+ module Lab42
2
+ module Tmux
3
+ NoSessionDefined = Class.new RuntimeError
4
+ end # module Tmux
5
+ end # module Lab42
@@ -0,0 +1,13 @@
1
+ module Lab42
2
+ module Tmux
3
+ module Interface extend self
4
+ def command *args
5
+ p args
6
+ %x{ tmux #{ args.join ' ' } }
7
+ end
8
+ def query *args
9
+ system "tmux #{ args.join ' ' }"
10
+ end
11
+ end # module Interface
12
+ end # module Tmux
13
+ end # module Lab42
@@ -0,0 +1,15 @@
1
+ require_relative 'parameter_helpers'
2
+
3
+ module Lab42
4
+ module Tmux
5
+ class Session
6
+ module Commands
7
+ def new_window name
8
+ @win_number += 1
9
+ commands << %W{ new-window #{session_address} -n #{name} }
10
+ end
11
+ end # module Commands
12
+ include Commands
13
+ end # class Session
14
+ end # module Tmux
15
+ end # module Lab42
@@ -0,0 +1,12 @@
1
+ module Lab42
2
+ module Tmux
3
+ class Session
4
+ module ParameterHelpers
5
+ def session_address
6
+ "-t #{name}"
7
+ end
8
+ end # module ParameterHelpers
9
+ include ParameterHelpers
10
+ end # class Session
11
+ end # module Tmux
12
+ end # module Lab42
@@ -0,0 +1,78 @@
1
+ require_relative 'errors'
2
+ require_relative 'session/commands'
3
+
4
+ module Lab42
5
+ module Tmux
6
+ class Session
7
+ attr_reader :commands, :name, :win_number
8
+
9
+ def define block
10
+ instance_exec( &block )
11
+ end
12
+
13
+ def run!
14
+ run
15
+ run_registered_commands
16
+ end
17
+
18
+ def run
19
+ create_session_and_windows unless running?
20
+ attach
21
+ end
22
+
23
+ private
24
+ def initialize sess_name
25
+ @name = sess_name
26
+ @win_number = 0
27
+ @commands = []
28
+
29
+ self.class.instance self
30
+ end
31
+
32
+ def attach
33
+ add_command 'attach-session', '-t', name
34
+ end
35
+
36
+ def add_command *args
37
+ commands << args
38
+ end
39
+ def create_session_and_windows
40
+ add_command 'source-file', File.join( ENV["HOME"], '.tmux.conf' )
41
+ add_command 'new-session', '-d', '-s', name, '-n', 'sh'
42
+ end
43
+
44
+ def running?
45
+ Interface.query 'has-session', '-t', name
46
+ end
47
+
48
+ def run_command command
49
+ case command
50
+ when String
51
+ Lab42::Tmux::Interface.command command
52
+ when Array
53
+ Lab42::Tmux::Interface.command( *command )
54
+ else
55
+ instance_exec( &command )
56
+ end
57
+ end
58
+
59
+ def run_registered_commands
60
+ commands.each do | command |
61
+ run_command command
62
+ end
63
+ end
64
+
65
+ class << self
66
+ def instance an_instance=nil
67
+ return @instance unless an_instance
68
+ @instance = an_instance
69
+ end
70
+
71
+ def run
72
+ raise Lab42::Tmux::NoSessionDefined, "you need to define a session with `new_session` in your script" unless instance
73
+ instance.run
74
+ end
75
+ end # class <<
76
+ end # class Session
77
+ end # module Tmux
78
+ end # module Lab42
@@ -0,0 +1,6 @@
1
+
2
+ module Lab42
3
+ module Tmux
4
+ VERSION = '0.0.1pre'
5
+ end # module Tmux
6
+ end # module Lab42
data/lib/lab42/tmux.rb ADDED
@@ -0,0 +1,20 @@
1
+ require_relative 'tmux/config'
2
+ require_relative 'tmux/interface'
3
+ require_relative 'tmux/session'
4
+
5
+ module Lab42
6
+ module Tmux
7
+
8
+ def new_session session_name=nil, &block
9
+ raise ArgumentError, 'No block provided' unless block
10
+ session = Session.new session_name || Config.session_name
11
+ session.define block if block
12
+ session.run!
13
+ end
14
+
15
+ end # module Tmux
16
+ end # module Lab42
17
+
18
+ at_exit do
19
+ Lab42::Tmux::Session.run
20
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lab42_tmux2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1pre
5
+ platform: ruby
6
+ authors:
7
+ - Robert Dober
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: forwarder2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.12
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.12
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-nav
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Create sessions with multiple windows from ruby
70
+ email: robert.dober@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - LICENSE
76
+ - README.md
77
+ - lib/lab42/tmux.rb
78
+ - lib/lab42/tmux/auto_import.rb
79
+ - lib/lab42/tmux/config.rb
80
+ - lib/lab42/tmux/errors.rb
81
+ - lib/lab42/tmux/interface.rb
82
+ - lib/lab42/tmux/session.rb
83
+ - lib/lab42/tmux/session/commands.rb
84
+ - lib/lab42/tmux/session/parameter_helpers.rb
85
+ - lib/lab42/tmux/version.rb
86
+ homepage: https://github.com/RobertDober/lab42_tmux
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '2.1'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.1
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Creating Tmux Windows And Panes Without Pains
110
+ test_files: []