lab42_tmux 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lab42_tmux +7 -6
- data/lib/lab42/tmux.rb +5 -2
- data/lib/lab42/tmux/command.rb +18 -40
- data/lib/lab42/tmux/commands.rb +0 -8
- data/lib/lab42/tmux/current_window.rb +28 -0
- data/lib/lab42/tmux/predefined/abstract_session.rb +15 -0
- data/lib/lab42/tmux/predefined/ruby_session.rb +3 -0
- data/lib/lab42/tmux/predefined/tmux_session.rb +19 -0
- data/lib/lab42/tmux/version.rb +2 -2
- data/lib/lab42/tmux/window/command.rb +2 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dc676118065197a5cd977d51690037f3814d2c2
|
4
|
+
data.tar.gz: c7584c2f8d3be9c1a02761224d79377b412f6ef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a8732386b3395e170c04043ba50ff8149e4f666f75729c8cc65236744e6e1cd13a40ea85b36f2f9dff89ac12a41634a50e40494ebf27546b87e91925ca0291
|
7
|
+
data.tar.gz: 39f97a1ab9130d792766aa1f9d43551503504fa91ed15507d98e0cdc02e83bc9896c9089641db821208895a72a0af482bbdaddf453602e9fc688cb2d190274d4
|
data/bin/lab42_tmux
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'lab42/tmux'
|
3
|
+
require 'lab42/tmux/predefined/tmux_session'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
begin
|
6
|
+
Lab42::Tmux::Predefined::TmuxSession.new( *ARGV.dup ).exec!
|
7
|
+
rescue ArgumentError => ae
|
8
|
+
$stderr.puts ae.message
|
9
|
+
exit -1
|
10
|
+
end
|
data/lib/lab42/tmux.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'lab42/options'
|
2
2
|
require 'lab42/tmux/core_helpers'
|
3
3
|
require 'lab42/tmux/commands'
|
4
|
+
require 'lab42/tmux/command'
|
4
5
|
require 'lab42/tmux/window'
|
5
6
|
require 'lab42/tmux/extensions/ostruct'
|
6
7
|
require 'lab42/tmux/extensions/hash'
|
@@ -10,12 +11,13 @@ require 'lab42/tmux/helpers'
|
|
10
11
|
module Lab42
|
11
12
|
class Tmux
|
12
13
|
include Commands
|
14
|
+
include Command
|
13
15
|
include Helpers
|
14
16
|
|
15
17
|
attr_reader :commands, :options, :project_home, :session_name, :windows
|
16
18
|
|
17
19
|
def add_window name=nil, options={}, &blk
|
18
|
-
window = Window.new windows.size, self, name: name, command: options[:command]
|
20
|
+
window = Window.new windows.size.succ, self, name: name, command: options[:command]
|
19
21
|
windows << window
|
20
22
|
|
21
23
|
window.instance_eval_or_call blk if blk
|
@@ -50,6 +52,8 @@ module Lab42
|
|
50
52
|
|
51
53
|
def process_options
|
52
54
|
@project_home = options.args.first
|
55
|
+
@project_home = File.join Dir.pwd, @project_home unless
|
56
|
+
!@project_home || %r{\A[/~]} === @project_home
|
53
57
|
@session_name = File.basename project_home rescue nil
|
54
58
|
end
|
55
59
|
|
@@ -63,7 +67,6 @@ module Lab42
|
|
63
67
|
return if session_exists?
|
64
68
|
tmux_new_session
|
65
69
|
tmux_source_file
|
66
|
-
tmux_no_session_rename
|
67
70
|
end
|
68
71
|
|
69
72
|
def session_exists?
|
data/lib/lab42/tmux/command.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'lab42/tmux/current_window'
|
1
2
|
class Array
|
2
3
|
def mk_string *args, &blk
|
3
4
|
args = [' '] if args.empty?
|
@@ -8,35 +9,13 @@ end # class Array
|
|
8
9
|
module Lab42
|
9
10
|
class Tmux
|
10
11
|
module Command
|
12
|
+
include CurrentWindow
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
window = [@options.session_name, tmux_current_window_number].join(":")
|
18
|
-
"-t #{window}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def tmux_current_window_command cmd, *args
|
22
|
-
args = args.compact
|
23
|
-
arguments = args.empty? ? "" : " #{args.join(" ")}"
|
24
|
-
tmux "#{cmd} #{tmux_current_window}#{arguments}"
|
25
|
-
end
|
26
|
-
|
27
|
-
def tmux_current_window_number
|
28
|
-
@__tmux_current_window_number__ ||= 0
|
29
|
-
end
|
30
|
-
|
31
|
-
def tmux_current_window_number= new_val
|
32
|
-
@__tmux_current_window_number__ = new_val
|
33
|
-
end
|
34
|
-
|
35
|
-
def tmux_execute_window_commands
|
36
|
-
( @tmux_window_precommands || [] ).each do | blk |
|
37
|
-
blk.()
|
38
|
-
end
|
39
|
-
end
|
14
|
+
# def tmux_execute_window_commands
|
15
|
+
# ( @tmux_window_precommands || [] ).each do | blk |
|
16
|
+
# blk.()
|
17
|
+
# end
|
18
|
+
# end
|
40
19
|
|
41
20
|
def tmux_increase_current_window_number by=1
|
42
21
|
self.tmux_current_window_number += by
|
@@ -44,19 +23,18 @@ module Lab42
|
|
44
23
|
|
45
24
|
# tmux new-session -s $session_name -n console -d
|
46
25
|
def tmux_new_session params=nil
|
47
|
-
if
|
48
|
-
tmux
|
26
|
+
if session_exists?
|
27
|
+
system "tmux attach -t #{session_name}"
|
49
28
|
exit 0
|
50
29
|
end
|
51
30
|
suffix = params ? " #{params}" : ""
|
52
|
-
session_name = @options.session_name
|
53
31
|
tmux "new-session -s #{session_name} -d#{suffix}"
|
54
|
-
|
55
|
-
|
32
|
+
unless @options.no_source_file || @options.tmux_source_file.nil?
|
33
|
+
tmux "source-file #{@options.tmux_source_file}"
|
34
|
+
end
|
56
35
|
tmux "set-window-option -g automatic-rename off"
|
57
|
-
|
58
|
-
|
59
|
-
tmux "attach -t #{session_name}"
|
36
|
+
unless @options.no_cd
|
37
|
+
tmux_project_home
|
60
38
|
end
|
61
39
|
end
|
62
40
|
|
@@ -87,10 +65,10 @@ module Lab42
|
|
87
65
|
tmux_send_keys [@options.cmd_prefix, cmd].mk_string, eol
|
88
66
|
end
|
89
67
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
68
|
+
def tmux_project_home dir=project_home
|
69
|
+
dir = File.join project_home, dir if dir && %r{\A[^/~]} === dir
|
70
|
+
tmux_send_keys "cd #{dir}"
|
71
|
+
end
|
94
72
|
|
95
73
|
def tmux_register_window_command noexec=false, &blk
|
96
74
|
blk.() unless noexec
|
data/lib/lab42/tmux/commands.rb
CHANGED
@@ -4,14 +4,6 @@ module Lab42
|
|
4
4
|
attr_accessor :window_count
|
5
5
|
def tmux cmd; commands << "tmux #{cmd}" end
|
6
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
7
|
def tmux_source_file
|
16
8
|
tmux "source-file #{options.source_file || File.join( ENV["HOME"], ".tmux.conf" )}"
|
17
9
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Lab42
|
2
|
+
class Tmux
|
3
|
+
module CurrentWindow
|
4
|
+
|
5
|
+
def tmux_current_window
|
6
|
+
"-t #{tmux_current_window_designation}"
|
7
|
+
end
|
8
|
+
|
9
|
+
def tmux_current_window_command cmd, *args
|
10
|
+
args = args.compact
|
11
|
+
arguments = args.empty? ? "" : " #{args.join(" ")}"
|
12
|
+
tmux "#{cmd} #{tmux_current_window}#{arguments}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def tmux_current_window_designation
|
16
|
+
[session_name, tmux_current_window_number].join(":")
|
17
|
+
end
|
18
|
+
def tmux_current_window_number
|
19
|
+
@__tmux_current_window_number__ ||= 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def tmux_current_window_number= new_val
|
23
|
+
@__tmux_current_window_number__ = new_val
|
24
|
+
end
|
25
|
+
|
26
|
+
end # module CurrentWindow
|
27
|
+
end # class Tmux
|
28
|
+
end # module Lab42
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'lab42/tmux'
|
2
|
+
require 'forwarder'
|
3
|
+
|
4
|
+
module Lab42
|
5
|
+
class Tmux
|
6
|
+
module Predefined
|
7
|
+
module AbstractSession
|
8
|
+
attr_reader :tmux
|
9
|
+
extend Forwarder
|
10
|
+
forward_all :exec!, :render, to: :tmux
|
11
|
+
end # module AbstractSession
|
12
|
+
end # module Predefined
|
13
|
+
end # class Tmux
|
14
|
+
end # module Lab42
|
15
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'lab42/tmux/predefined/abstract_session'
|
2
|
+
|
3
|
+
module Lab42
|
4
|
+
class Tmux
|
5
|
+
module Predefined
|
6
|
+
class TmuxSession
|
7
|
+
include AbstractSession
|
8
|
+
private
|
9
|
+
def initialize *args, &blk
|
10
|
+
@tmux = Lab42::Tmux.new args do
|
11
|
+
options.wins.to_i.times do
|
12
|
+
add_window "sh"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end # cmass TmuxSession
|
17
|
+
end # module Predefined
|
18
|
+
end # class Tmux
|
19
|
+
end # module Lab42
|
data/lib/lab42/tmux/version.rb
CHANGED
@@ -6,12 +6,9 @@ module Lab42
|
|
6
6
|
module Command
|
7
7
|
include VimCommand
|
8
8
|
extend Forwarder
|
9
|
-
forward_all :lprefix, :session_name, to: :session
|
10
|
-
|
11
|
-
def tmux *args
|
12
|
-
added_commands << session.tmux( *args )
|
13
|
-
end
|
9
|
+
forward_all :lprefix, :session_name, :tmux, to: :session
|
14
10
|
|
11
|
+
# TODO: Check for dead code here!
|
15
12
|
def tmux_new_window( rename: false )
|
16
13
|
[ tmux( "new-window -t #{session_name}#{new_window_name}" ) ] +
|
17
14
|
(rename ? [] : [
|
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.3
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lab42_options
|
@@ -106,12 +106,15 @@ extra_rdoc_files: []
|
|
106
106
|
files:
|
107
107
|
- lib/lab42/tmux.rb
|
108
108
|
- lib/lab42/tmux/core_helpers.rb
|
109
|
+
- lib/lab42/tmux/current_window.rb
|
109
110
|
- lib/lab42/tmux/extensions/ostruct.rb
|
110
111
|
- lib/lab42/tmux/extensions/object.rb
|
111
112
|
- lib/lab42/tmux/extensions/hash.rb
|
112
113
|
- lib/lab42/tmux/options.rb
|
113
114
|
- lib/lab42/tmux/helpers.rb
|
114
115
|
- lib/lab42/tmux/version.rb
|
116
|
+
- lib/lab42/tmux/predefined/tmux_session.rb
|
117
|
+
- lib/lab42/tmux/predefined/abstract_session.rb
|
115
118
|
- lib/lab42/tmux/predefined/ruby_session.rb
|
116
119
|
- lib/lab42/tmux/commands.rb
|
117
120
|
- lib/lab42/tmux/window/command/vim_command.rb
|