lab42_tmux 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/bin/lab42_ruby_session +4 -0
- data/lib/lab42/tmux/command.rb +5 -9
- data/lib/lab42/tmux/commands.rb +2 -2
- data/lib/lab42/tmux/extensions/hash.rb +8 -0
- data/lib/lab42/tmux/extensions/object.rb +10 -0
- data/lib/lab42/tmux/extensions/ostruct.rb +5 -0
- data/lib/lab42/tmux/helpers.rb +15 -0
- data/lib/lab42/tmux/predefined/ruby_session.rb +41 -0
- data/lib/lab42/tmux/version.rb +1 -1
- data/lib/lab42/tmux/window/command/vim_command.rb +30 -0
- data/lib/lab42/tmux/window/command.rb +24 -4
- data/lib/lab42/tmux/window.rb +32 -11
- data/lib/lab42/tmux.rb +26 -35
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f15f6f7b7cc46ac2975640531b3cdccfcb5d6d90
|
4
|
+
data.tar.gz: 0af03c1673a9bde59186e9301e8eabdfed12e35d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aed7ad5a9495ded7b32b3a9d2a12223c630683f77a2403a876e129041bc40b84afe68793b4e7d6a3ecea898b555d8e23ec0304118d38e21d62f55cf0f20b47f
|
7
|
+
data.tar.gz: 6b8815601f598e2b85f6838786c000802ee44409c7ca9e6681b3d14c01eeec74c142fa33e4ce13f27156cc4d0b1989c4a23a29233c968c2c4b74a65df02104c6
|
data/README.md
CHANGED
@@ -6,6 +6,24 @@
|
|
6
6
|
|
7
7
|
#### lab42\_tmux
|
8
8
|
|
9
|
+
```
|
10
|
+
lab42_ruby_session project_home [:dry_run] [repl: <repl and params>]
|
11
|
+
```
|
12
|
+
|
13
|
+
Opens a tmux session with the following windows
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
repl, defaulting to "irb"
|
19
|
+
vi "vi ."
|
20
|
+
lib "vi lib"
|
21
|
+
spec "vi spec" iff project_home/spec exists
|
22
|
+
features "vi feartures" iff project_home/featutes exists
|
23
|
+
cucu "sh" iff project_home/featutes exists
|
24
|
+
a shell
|
25
|
+
|
26
|
+
*Broken in 0.0.2*
|
9
27
|
```
|
10
28
|
lab42_tmux some_path [windows: n]
|
11
29
|
```
|
data/lib/lab42/tmux/command.rb
CHANGED
@@ -10,11 +10,7 @@ module Lab42
|
|
10
10
|
module Command
|
11
11
|
|
12
12
|
def tmux cmd
|
13
|
-
|
14
|
-
puts "tmux #{cmd}"
|
15
|
-
else
|
16
|
-
system "tmux #{cmd}"
|
17
|
-
end
|
13
|
+
commands << "tmux #{cmd}"
|
18
14
|
end
|
19
15
|
|
20
16
|
def tmux_current_window
|
@@ -91,10 +87,10 @@ module Lab42
|
|
91
87
|
tmux_send_keys [@options.cmd_prefix, cmd].mk_string, eol
|
92
88
|
end
|
93
89
|
|
94
|
-
def tmux_project_home dir=nil
|
95
|
-
|
96
|
-
|
97
|
-
end
|
90
|
+
# def tmux_project_home dir=nil
|
91
|
+
# dir = File.join @options.dir, dir if dir && %r{\A[^/]} === dir
|
92
|
+
# tmux_send_keys "cd #{dir || @options.dir}"
|
93
|
+
# end
|
98
94
|
|
99
95
|
def tmux_register_window_command noexec=false, &blk
|
100
96
|
blk.() unless noexec
|
data/lib/lab42/tmux/commands.rb
CHANGED
@@ -2,7 +2,7 @@ module Lab42
|
|
2
2
|
class Tmux
|
3
3
|
module Commands
|
4
4
|
attr_accessor :window_count
|
5
|
-
def tmux cmd; "tmux #{cmd}" end
|
5
|
+
def tmux cmd; commands << "tmux #{cmd}" end
|
6
6
|
|
7
7
|
def tmux_new_session cmd=nil
|
8
8
|
tmux "new-session -s #{session_name} -d#{lprefix cmd}"
|
@@ -13,7 +13,7 @@ module Lab42
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def tmux_source_file
|
16
|
-
|
16
|
+
tmux "source-file #{options.source_file || File.join( ENV["HOME"], ".tmux.conf" )}"
|
17
17
|
end
|
18
18
|
|
19
19
|
def lprefix cmd, prefix=" "
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lab42
|
2
|
+
class Tmux
|
3
|
+
module Helpers
|
4
|
+
def if_dir dir, &blk
|
5
|
+
return unless File.directory? expand_dir dir
|
6
|
+
instance_eval_or_call blk
|
7
|
+
end
|
8
|
+
|
9
|
+
def expand_dir dir
|
10
|
+
return dir if %r{\A/} === dir
|
11
|
+
File.join project_home, dir
|
12
|
+
end
|
13
|
+
end # module Helpers
|
14
|
+
end # class Tmux
|
15
|
+
end # module Lab42
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'lab42/tmux'
|
2
|
+
require 'forwarder'
|
3
|
+
|
4
|
+
module Lab42
|
5
|
+
class Tmux
|
6
|
+
module Predefined
|
7
|
+
class RubySession
|
8
|
+
attr_reader :tmux
|
9
|
+
extend Forwarder
|
10
|
+
forward_all :exec!, :render, to: :tmux
|
11
|
+
|
12
|
+
private
|
13
|
+
def initialize *args, &blk
|
14
|
+
@tmux = Lab42::Tmux.new args do
|
15
|
+
add_window "repl", command: options.fetch(:repl,"irb")
|
16
|
+
add_window "vi", command: "vi ."
|
17
|
+
# require 'pry'
|
18
|
+
# binding.pry
|
19
|
+
if_dir "lib" do
|
20
|
+
add_window "lib", command: "vi lib" do
|
21
|
+
vim_command "colorscheme morning"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
if_dir "spec" do
|
25
|
+
add_window "spec", command: "vi spec" do
|
26
|
+
vim_commands "colorscheme solarized", background: "light"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
if_dir "features" do
|
30
|
+
add_window "features", command: "vi features"
|
31
|
+
add_window "cucu"
|
32
|
+
end
|
33
|
+
add_window "sh"
|
34
|
+
# TODO: Specify this later if needed
|
35
|
+
# instance_eval_or_call blk if blk
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end # class RubySession
|
39
|
+
end # module Predefined
|
40
|
+
end # class Tmux
|
41
|
+
end # module Lab42
|
data/lib/lab42/tmux/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Lab42
|
2
|
+
class Tmux
|
3
|
+
class Window
|
4
|
+
module Command
|
5
|
+
module VimCommand
|
6
|
+
def vim_commands *cmds
|
7
|
+
cmds.each do | cmd |
|
8
|
+
vim_command cmd
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def vim_command cmd
|
13
|
+
case cmd
|
14
|
+
when Hash
|
15
|
+
vim_set_commands cmd
|
16
|
+
else
|
17
|
+
tmux_send_keys ":#{cmd}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def vim_set_commands set_cmds
|
22
|
+
set_cmds.each do |key, val|
|
23
|
+
tmux_send_keys ":set #{key}=#{val}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end # module VimCommand
|
27
|
+
end # module Command
|
28
|
+
end # class Window
|
29
|
+
end # class Tmux
|
30
|
+
end # module Lab42
|
@@ -1,25 +1,45 @@
|
|
1
1
|
require 'forwarder'
|
2
|
+
require 'lab42/tmux/window/command/vim_command.rb'
|
2
3
|
module Lab42
|
3
4
|
class Tmux
|
4
5
|
class Window
|
5
6
|
module Command
|
7
|
+
include VimCommand
|
6
8
|
extend Forwarder
|
7
|
-
forward_all :lprefix, :session_name,
|
9
|
+
forward_all :lprefix, :session_name, to: :session
|
10
|
+
|
11
|
+
def tmux *args
|
12
|
+
added_commands << session.tmux( *args )
|
13
|
+
end
|
8
14
|
|
9
15
|
def tmux_new_window( rename: false )
|
10
|
-
[ tmux( "new-window -t #{session_name}" ) ] +
|
16
|
+
[ tmux( "new-window -t #{session_name}#{new_window_name}" ) ] +
|
11
17
|
(rename ? [] : [
|
12
18
|
tmux( "set-window-option -t #{designation} automatic-rename off" ),
|
13
19
|
tmux( "set-window-option -t #{designation} allow-rename off" )
|
14
|
-
])
|
20
|
+
]) +
|
21
|
+
[tmux_cd_project_home] +
|
22
|
+
tmux_commands
|
15
23
|
end
|
16
24
|
|
17
25
|
def tmux_cd_project_home
|
18
26
|
tmux_send_keys "cd #{session.project_home}"
|
19
27
|
end
|
20
28
|
|
29
|
+
def tmux_commands
|
30
|
+
[(commands || [])].flatten.map{ |cmd|
|
31
|
+
tmux_send_keys cmd
|
32
|
+
}
|
33
|
+
end
|
21
34
|
def tmux_send_keys keys, cm: true
|
22
|
-
tmux "send-keys
|
35
|
+
tmux "send-keys -t #{designation} #{keys.inspect}#{lprefix( cm && "C-m" )}"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def new_window_name
|
40
|
+
with_present( :name ){ | name |
|
41
|
+
" -n #{name}"
|
42
|
+
}
|
23
43
|
end
|
24
44
|
|
25
45
|
end # module Command
|
data/lib/lab42/tmux/window.rb
CHANGED
@@ -1,22 +1,43 @@
|
|
1
1
|
require 'lab42/tmux/window/command'
|
2
|
+
require 'forwarder'
|
2
3
|
module Lab42
|
3
4
|
class Tmux
|
4
5
|
class Window
|
5
6
|
include Command
|
6
|
-
|
7
|
+
extend Forwarder
|
8
|
+
attr_reader :command, :name, :number, :session
|
9
|
+
forward_all :commands, :lprefix, :session_name, :tmux, to: :session
|
10
|
+
|
7
11
|
def designation
|
8
|
-
[
|
9
|
-
end
|
10
|
-
def render
|
11
|
-
[
|
12
|
-
tmux_new_window,
|
13
|
-
tmux_cd_project_home
|
14
|
-
].flatten
|
12
|
+
[session_name, number].join ":"
|
15
13
|
end
|
16
14
|
private
|
17
|
-
def initialize nb, session
|
18
|
-
|
19
|
-
|
15
|
+
def initialize nb, session, options={}
|
16
|
+
@session = session
|
17
|
+
@number = nb
|
18
|
+
@name = options[:name]
|
19
|
+
@command = options[:command]
|
20
|
+
tmux_window_commands
|
21
|
+
end
|
22
|
+
|
23
|
+
def tmux_window_command cmd, params
|
24
|
+
tmux "#{tmuxize cmd} -t #{designation} #{params}"
|
25
|
+
end
|
26
|
+
def tmux_window_commands
|
27
|
+
tmux "new-window -t #{session_name}#{name ? " -n #{name}" : ""}"
|
28
|
+
tmux_window_options
|
29
|
+
tmux_cd_project_home
|
30
|
+
tmux_send_keys command if command
|
31
|
+
end
|
32
|
+
|
33
|
+
def tmux_window_options( options: {} )
|
34
|
+
[:automatic_rename, :allow_rename].each do |option|
|
35
|
+
tmux_window_command :set_window_option, "#{tmuxize option} #{options[option] ? "on" : "off"}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def tmuxize sym
|
40
|
+
sym.to_s.gsub "_", "-"
|
20
41
|
end
|
21
42
|
end # class Window
|
22
43
|
end # class Tmux
|
data/lib/lab42/tmux.rb
CHANGED
@@ -2,20 +2,27 @@ require 'lab42/options'
|
|
2
2
|
require 'lab42/tmux/core_helpers'
|
3
3
|
require 'lab42/tmux/commands'
|
4
4
|
require 'lab42/tmux/window'
|
5
|
+
require 'lab42/tmux/extensions/ostruct'
|
6
|
+
require 'lab42/tmux/extensions/hash'
|
7
|
+
require 'lab42/tmux/extensions/object'
|
8
|
+
require 'lab42/tmux/helpers'
|
5
9
|
|
6
10
|
module Lab42
|
7
11
|
class Tmux
|
8
12
|
include Commands
|
13
|
+
include Helpers
|
9
14
|
|
10
|
-
|
11
|
-
attr_reader :project_home, :session_name
|
15
|
+
attr_reader :commands, :options, :project_home, :session_name, :windows
|
12
16
|
|
13
|
-
def add_window &blk
|
14
|
-
|
15
|
-
|
17
|
+
def add_window name=nil, options={}, &blk
|
18
|
+
window = Window.new windows.size, self, name: name, command: options[:command]
|
19
|
+
windows << window
|
20
|
+
|
21
|
+
window.instance_eval_or_call blk if blk
|
16
22
|
end
|
17
23
|
|
18
24
|
def current_window; windows.last end
|
25
|
+
def current_window?; !!current_window end
|
19
26
|
|
20
27
|
def exec!
|
21
28
|
if options.dry_run
|
@@ -26,57 +33,41 @@ module Lab42
|
|
26
33
|
end
|
27
34
|
|
28
35
|
def render
|
29
|
-
commands
|
30
|
-
render_new_session_or_empty +
|
31
|
-
render_final_attach_command
|
32
|
-
|
33
|
-
commands.join "\n"
|
36
|
+
(commands + final_attach_command).join "\n"
|
34
37
|
end
|
35
38
|
|
36
39
|
private
|
37
|
-
def initialize &blk
|
38
|
-
|
40
|
+
def initialize args, &blk
|
41
|
+
@options = Lab42::Options.new.parse( *args.dup )
|
42
|
+
@commands = []
|
43
|
+
@windows = []
|
39
44
|
process_options
|
40
45
|
raise ArgumentError, "unable to determine session name" unless session_name
|
41
46
|
raise ArgumentError, "no such directory #{project_home}" unless project_home && File.directory?( project_home )
|
42
|
-
|
47
|
+
session_commands
|
43
48
|
instance_eval_or_call blk
|
44
49
|
end
|
45
50
|
|
46
|
-
|
47
51
|
def process_options
|
48
52
|
@project_home = options.args.first
|
49
53
|
@session_name = File.basename project_home rescue nil
|
50
54
|
end
|
51
55
|
|
52
|
-
def
|
56
|
+
def final_attach_command
|
53
57
|
[
|
54
|
-
tmux
|
58
|
+
"tmux attach -t #{session_name}"
|
55
59
|
]
|
56
60
|
end
|
57
61
|
|
58
|
-
def
|
59
|
-
if session_exists?
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
62
|
+
def session_commands
|
63
|
+
return if session_exists?
|
64
|
+
tmux_new_session
|
65
|
+
tmux_source_file
|
66
|
+
tmux_no_session_rename
|
77
67
|
end
|
78
68
|
|
79
69
|
def session_exists?
|
70
|
+
return false if options.dry_run
|
80
71
|
system "tmux has-session -t #{session_name}"
|
81
72
|
$?.to_i.zero?
|
82
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lab42_tmux
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lab42_options
|
@@ -100,20 +100,28 @@ description: A Gem that will give us helpers to dry up the creation of TMUX wind
|
|
100
100
|
email: robert.dober@gmail.com
|
101
101
|
executables:
|
102
102
|
- lab42_tmux
|
103
|
+
- lab42_ruby_session
|
103
104
|
extensions: []
|
104
105
|
extra_rdoc_files: []
|
105
106
|
files:
|
106
107
|
- lib/lab42/tmux.rb
|
107
108
|
- lib/lab42/tmux/core_helpers.rb
|
109
|
+
- lib/lab42/tmux/extensions/ostruct.rb
|
110
|
+
- lib/lab42/tmux/extensions/object.rb
|
111
|
+
- lib/lab42/tmux/extensions/hash.rb
|
108
112
|
- lib/lab42/tmux/options.rb
|
113
|
+
- lib/lab42/tmux/helpers.rb
|
109
114
|
- lib/lab42/tmux/version.rb
|
115
|
+
- lib/lab42/tmux/predefined/ruby_session.rb
|
110
116
|
- lib/lab42/tmux/commands.rb
|
117
|
+
- lib/lab42/tmux/window/command/vim_command.rb
|
111
118
|
- lib/lab42/tmux/window/command.rb
|
112
119
|
- lib/lab42/tmux/command.rb
|
113
120
|
- lib/lab42/tmux/window.rb
|
114
121
|
- LICENSE
|
115
122
|
- README.md
|
116
123
|
- bin/lab42_tmux
|
124
|
+
- bin/lab42_ruby_session
|
117
125
|
homepage: https://github.com/RobertDober/lab42_tmux
|
118
126
|
licenses:
|
119
127
|
- MIT
|