lab42_tmux 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +10 -0
- data/README.md +14 -0
- data/bin/lab42_tmux +9 -0
- data/lib/lab42/tmux/command.rb +121 -0
- data/lib/lab42/tmux/commands.rb +25 -0
- data/lib/lab42/tmux/core_helpers.rb +10 -0
- data/lib/lab42/tmux/options.rb +22 -0
- data/lib/lab42/tmux/version.rb +5 -0
- data/lib/lab42/tmux/window/command.rb +28 -0
- data/lib/lab42/tmux/window.rb +23 -0
- data/lib/lab42/tmux.rb +84 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a9e3d3a2d988cc697b9883c34ff111da4d293a1
|
4
|
+
data.tar.gz: 2935cfbf73d68006024b52c06fb8970f76c60b66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02bee1fd05f6dc7cfa8548e083dd4ecc62a155662238ac0396a44bb216e39a99797ce96379c41b668a99ee971accac87151d1469db3a4e0a365cf1524fc0fb6e
|
7
|
+
data.tar.gz: e35038f4a48f418c9d2f3310d0f3d528eeef4dc08ec39d8486353fda9e6e339b9afa6e762000def3a3d3f2ff445224b210e14a603033de66cbca106096db8feb
|
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,14 @@
|
|
1
|
+
# Lab42, Programmers' Best Friend In Ruby 2
|
2
|
+
|
3
|
+
## Tmux
|
4
|
+
|
5
|
+
### Predefined Scripts
|
6
|
+
|
7
|
+
#### lab42\_tmux
|
8
|
+
|
9
|
+
```
|
10
|
+
lab42_tmux some_path [windows: n]
|
11
|
+
```
|
12
|
+
|
13
|
+
If a session with the basename of `some_path` exists will attach to it. Otherwise
|
14
|
+
will open a session with that name and n *additional* windows, each window will be cwed into `some_path.
|
data/bin/lab42_tmux
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
class Array
|
2
|
+
def mk_string *args, &blk
|
3
|
+
args = [' '] if args.empty?
|
4
|
+
compact.join( *args, &blk )
|
5
|
+
end
|
6
|
+
end # class Array
|
7
|
+
|
8
|
+
module Lab42
|
9
|
+
class Tmux
|
10
|
+
module Command
|
11
|
+
|
12
|
+
def tmux cmd
|
13
|
+
if @options.dry_run
|
14
|
+
puts "tmux #{cmd}"
|
15
|
+
else
|
16
|
+
system "tmux #{cmd}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def tmux_current_window
|
21
|
+
window = [@options.session_name, tmux_current_window_number].join(":")
|
22
|
+
"-t #{window}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def tmux_current_window_command cmd, *args
|
26
|
+
args = args.compact
|
27
|
+
arguments = args.empty? ? "" : " #{args.join(" ")}"
|
28
|
+
tmux "#{cmd} #{tmux_current_window}#{arguments}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def tmux_current_window_number
|
32
|
+
@__tmux_current_window_number__ ||= 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def tmux_current_window_number= new_val
|
36
|
+
@__tmux_current_window_number__ = new_val
|
37
|
+
end
|
38
|
+
|
39
|
+
def tmux_execute_window_commands
|
40
|
+
( @tmux_window_precommands || [] ).each do | blk |
|
41
|
+
blk.()
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def tmux_increase_current_window_number by=1
|
46
|
+
self.tmux_current_window_number += by
|
47
|
+
end
|
48
|
+
|
49
|
+
# tmux new-session -s $session_name -n console -d
|
50
|
+
def tmux_new_session params=nil
|
51
|
+
if has_tmux_session?
|
52
|
+
tmux "attach -t #{@options.session_name}"
|
53
|
+
exit 0
|
54
|
+
end
|
55
|
+
suffix = params ? " #{params}" : ""
|
56
|
+
session_name = @options.session_name
|
57
|
+
tmux "new-session -s #{session_name} -d#{suffix}"
|
58
|
+
return if @options.no_source_file || @options.tmux_source_file.nil?
|
59
|
+
tmux "source-file #{@options.tmux_source_file}"
|
60
|
+
tmux "set-window-option -g automatic-rename off"
|
61
|
+
tmux_project_home
|
62
|
+
at_exit do
|
63
|
+
tmux "attach -t #{session_name}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def tmux_new_window name=nil, dir=nil
|
68
|
+
tmux_increase_current_window_number
|
69
|
+
suffix = name ? %{ -n "#{name}"} : nil
|
70
|
+
tmux "new-window -t #{@options.session_name}#{suffix}"
|
71
|
+
tmux_set_window_options "automatic-rename off", "allow-rename off"
|
72
|
+
tmux_project_home dir
|
73
|
+
tmux_execute_window_commands
|
74
|
+
end
|
75
|
+
|
76
|
+
def tmux_open_vim options={}
|
77
|
+
dir = options.delete( :dir ){ "." }
|
78
|
+
tmux_send_keys "vi #{dir}"
|
79
|
+
options.each do | cmd, params |
|
80
|
+
command = ":#{[cmd,params].compact.join(" ")}"
|
81
|
+
tmux_send_keys command
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def tmux_open_irb options={}
|
86
|
+
lib = options.delete( :lib ){ "./lib" }
|
87
|
+
tmux_send_keys "irb -I#{lib}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def tmux_prefixed_command cmd, eol=true
|
91
|
+
tmux_send_keys [@options.cmd_prefix, cmd].mk_string, eol
|
92
|
+
end
|
93
|
+
|
94
|
+
def tmux_project_home dir=nil
|
95
|
+
dir = File.join @options.dir, dir if dir && %r{\A[^/]} === dir
|
96
|
+
tmux_send_keys "cd #{dir || @options.dir}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def tmux_register_window_command noexec=false, &blk
|
100
|
+
blk.() unless noexec
|
101
|
+
@tmux_window_precommands ||= []
|
102
|
+
@tmux_window_precommands << blk
|
103
|
+
end
|
104
|
+
|
105
|
+
def tmux_send_keys keys, eol=true
|
106
|
+
suffix = eol ? " C-m" : nil
|
107
|
+
tmux_current_window_command "send-keys", %{"#{keys}"}, suffix
|
108
|
+
end
|
109
|
+
|
110
|
+
def tmux_set_window_option option
|
111
|
+
tmux_current_window_command "set-window-option", option
|
112
|
+
end
|
113
|
+
|
114
|
+
def tmux_set_window_options *options
|
115
|
+
options.each do | option |
|
116
|
+
tmux_set_window_option option
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Lab42
|
2
|
+
class Tmux
|
3
|
+
module Commands
|
4
|
+
attr_accessor :window_count
|
5
|
+
def tmux cmd; "tmux #{cmd}" end
|
6
|
+
|
7
|
+
def tmux_new_session cmd=nil
|
8
|
+
tmux "new-session -s #{session_name} -d#{lprefix cmd}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def tmux_no_session_rename
|
12
|
+
tmux "set-window-option -g automatic-rename off" unless options.no_session_rename
|
13
|
+
end
|
14
|
+
|
15
|
+
def tmux_source_file
|
16
|
+
"tmux source-file #{options.source_file || File.join( ENV["HOME"], ".tmux.conf" )}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def lprefix cmd, prefix=" "
|
20
|
+
cmd ? "#{prefix}#{cmd}" : ""
|
21
|
+
end
|
22
|
+
|
23
|
+
end # module Commands
|
24
|
+
end # class Tmux
|
25
|
+
end # module Lab42
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'lab42/tmux/options/api'
|
3
|
+
include Lab42::Tmux::Options::Api
|
4
|
+
|
5
|
+
@options = {}
|
6
|
+
@options["dir"] = ARGV.first
|
7
|
+
e = ARGV[1..-1]
|
8
|
+
e = (e || []).enum_for(:each)
|
9
|
+
loop do
|
10
|
+
case current = e.next
|
11
|
+
when /\A:(\w+)/
|
12
|
+
@options[$1] = true
|
13
|
+
when /(\w+):/
|
14
|
+
@options[$1] = e.next
|
15
|
+
else
|
16
|
+
raise ArgumentError, ele
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@options = OpenStruct.new @options
|
21
|
+
@options.session_name ||= @options.dir && File.basename( @options.dir )
|
22
|
+
@options.tmux_source_file ||= "~/.tmux.conf"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'forwarder'
|
2
|
+
module Lab42
|
3
|
+
class Tmux
|
4
|
+
class Window
|
5
|
+
module Command
|
6
|
+
extend Forwarder
|
7
|
+
forward_all :lprefix, :session_name, :tmux, to: :session
|
8
|
+
|
9
|
+
def tmux_new_window( rename: false )
|
10
|
+
[ tmux( "new-window -t #{session_name}" ) ] +
|
11
|
+
(rename ? [] : [
|
12
|
+
tmux( "set-window-option -t #{designation} automatic-rename off" ),
|
13
|
+
tmux( "set-window-option -t #{designation} allow-rename off" )
|
14
|
+
])
|
15
|
+
end
|
16
|
+
|
17
|
+
def tmux_cd_project_home
|
18
|
+
tmux_send_keys "cd #{session.project_home}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def tmux_send_keys keys, cm: true
|
22
|
+
tmux "send-keys -t #{designation} #{keys.inspect}#{lprefix( cm && "C-m" )}"
|
23
|
+
end
|
24
|
+
|
25
|
+
end # module Command
|
26
|
+
end # class Window
|
27
|
+
end # class Tmux
|
28
|
+
end # module Lab42
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'lab42/tmux/window/command'
|
2
|
+
module Lab42
|
3
|
+
class Tmux
|
4
|
+
class Window
|
5
|
+
include Command
|
6
|
+
attr_accessor :number, :session
|
7
|
+
def designation
|
8
|
+
[session.session_name, number].join ":"
|
9
|
+
end
|
10
|
+
def render
|
11
|
+
[
|
12
|
+
tmux_new_window,
|
13
|
+
tmux_cd_project_home
|
14
|
+
].flatten
|
15
|
+
end
|
16
|
+
private
|
17
|
+
def initialize nb, session
|
18
|
+
self.session = session
|
19
|
+
self.number = nb
|
20
|
+
end
|
21
|
+
end # class Window
|
22
|
+
end # class Tmux
|
23
|
+
end # module Lab42
|
data/lib/lab42/tmux.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'lab42/options'
|
2
|
+
require 'lab42/tmux/core_helpers'
|
3
|
+
require 'lab42/tmux/commands'
|
4
|
+
require 'lab42/tmux/window'
|
5
|
+
|
6
|
+
module Lab42
|
7
|
+
class Tmux
|
8
|
+
include Commands
|
9
|
+
|
10
|
+
attr_accessor :options, :windows
|
11
|
+
attr_reader :project_home, :session_name
|
12
|
+
|
13
|
+
def add_window &blk
|
14
|
+
self.windows << Window.new( windows.size, self )
|
15
|
+
instance_eval_or_call blk if blk
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_window; windows.last end
|
19
|
+
|
20
|
+
def exec!
|
21
|
+
if options.dry_run
|
22
|
+
puts render
|
23
|
+
else
|
24
|
+
exec render
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def render
|
29
|
+
commands =
|
30
|
+
render_new_session_or_empty +
|
31
|
+
render_final_attach_command
|
32
|
+
|
33
|
+
commands.join "\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def initialize &blk
|
38
|
+
self.options = Lab42::Options.new.parse( *ARGV.dup )
|
39
|
+
process_options
|
40
|
+
raise ArgumentError, "unable to determine session name" unless session_name
|
41
|
+
raise ArgumentError, "no such directory #{project_home}" unless project_home && File.directory?( project_home )
|
42
|
+
self.windows = [Window.new( 0, self )]
|
43
|
+
instance_eval_or_call blk
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def process_options
|
48
|
+
@project_home = options.args.first
|
49
|
+
@session_name = File.basename project_home rescue nil
|
50
|
+
end
|
51
|
+
|
52
|
+
def render_final_attach_command
|
53
|
+
[
|
54
|
+
tmux( "attach -t #{session_name}" )
|
55
|
+
]
|
56
|
+
end
|
57
|
+
|
58
|
+
def render_new_session_or_empty
|
59
|
+
if session_exists?
|
60
|
+
[]
|
61
|
+
else
|
62
|
+
render_session_commands +
|
63
|
+
render_window_commands
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def render_session_commands
|
68
|
+
[
|
69
|
+
tmux_new_session,
|
70
|
+
tmux_source_file,
|
71
|
+
tmux_no_session_rename
|
72
|
+
].compact
|
73
|
+
end
|
74
|
+
|
75
|
+
def render_window_commands
|
76
|
+
windows.map(&:render).flatten
|
77
|
+
end
|
78
|
+
|
79
|
+
def session_exists?
|
80
|
+
system "tmux has-session -t #{session_name}"
|
81
|
+
$?.to_i.zero?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end # module Lab42
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lab42_tmux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Dober
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lab42_options
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: forwarder19
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.12
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.12
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cucumber
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.13.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.13.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.3
|
97
|
+
description: A Gem that will give us helpers to dry up the creation of TMUX windows
|
98
|
+
and panes, adding some predefind layouts which are a good starting point for the
|
99
|
+
usage of this gem
|
100
|
+
email: robert.dober@gmail.com
|
101
|
+
executables:
|
102
|
+
- lab42_tmux
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- lib/lab42/tmux.rb
|
107
|
+
- lib/lab42/tmux/core_helpers.rb
|
108
|
+
- lib/lab42/tmux/options.rb
|
109
|
+
- lib/lab42/tmux/version.rb
|
110
|
+
- lib/lab42/tmux/commands.rb
|
111
|
+
- lib/lab42/tmux/window/command.rb
|
112
|
+
- lib/lab42/tmux/command.rb
|
113
|
+
- lib/lab42/tmux/window.rb
|
114
|
+
- LICENSE
|
115
|
+
- README.md
|
116
|
+
- bin/lab42_tmux
|
117
|
+
homepage: https://github.com/RobertDober/lab42_tmux
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 2.0.0
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.0.3
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Creating Tmux Windows And Panes Without Pains
|
141
|
+
test_files: []
|