lab419_tmux 0.1.0
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 +32 -0
- data/bin/lab419_tmux +12 -0
- data/lib/lab419/tmux.rb +0 -0
- data/lib/lab419/tmux/command.rb +123 -0
- data/lib/lab419/tmux/options.rb +22 -0
- data/lib/lab419/tmux/options/api.rb +20 -0
- data/lib/lab419/tmux/version.rb +5 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c863a86d859f3edec55d75620495a4981eea931
|
4
|
+
data.tar.gz: f31777265cc87f3050e33c643aed8d039ef65e82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f81f7ff65a0454d10e0e8ebec2f425d69c3b093c53fae6eb6e564927acae4d45c4636eafe1852c9e5692fa3c1591b6333785a29b0b3387e91a450bc5e46235f4
|
7
|
+
data.tar.gz: 3ab804f54412823cace789616122bd2837537d5befbe3f550b7afc5644d2d019266e80c976f0ff66e157113e9afee1f1f1c9d883d915152f0717e1e72e1ef5bc
|
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,32 @@
|
|
1
|
+
# Lab419, Programmers' Best Friend
|
2
|
+
|
3
|
+
## Tmux
|
4
|
+
|
5
|
+
Tmux needs Ruby 2.
|
6
|
+
|
7
|
+
### Common Observations
|
8
|
+
|
9
|
+
Unless otherwise stated all `lab419_*` commands implemented by this gem are determining a `session\_name` as the basename of
|
10
|
+
the first argument, which shall be an existing directory.
|
11
|
+
|
12
|
+
In case a tmux session with the thusly determined `session_name` already exists the aforementioned script just attaches to the session with
|
13
|
+
the `tmux attach` command. Otherwise a session with name `session_name` is created and windows and panes are created and configured as specified
|
14
|
+
by the script in question and its parameters.
|
15
|
+
|
16
|
+
|
17
|
+
### Predefined Scripts
|
18
|
+
|
19
|
+
#### lab419\_tmux
|
20
|
+
|
21
|
+
```
|
22
|
+
lab419_tmux some_path [windows: n]
|
23
|
+
```
|
24
|
+
|
25
|
+
Will open a session with n *additional* windows, each window will be cwed into `some_path`
|
26
|
+
|
27
|
+
|
28
|
+
### Tmux::Command API
|
29
|
+
|
30
|
+
This is inherited from my private, non TDD :@, driven project, only the script present in this release is protected by
|
31
|
+
cucumber specs. The `Lab419::Tmux::Command` API will be speced and documented in later versions of this gem. This version serves
|
32
|
+
as a useable tool but do not consider the API stable.
|
data/bin/lab419_tmux
ADDED
data/lib/lab419/tmux.rb
ADDED
File without changes
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'lab419/tmux/options/api'
|
2
|
+
class Array
|
3
|
+
def mk_string *args, &blk
|
4
|
+
args = [' '] if args.empty?
|
5
|
+
compact.join( *args, &blk )
|
6
|
+
end
|
7
|
+
end # class Array
|
8
|
+
|
9
|
+
module Lab419
|
10
|
+
module Tmux
|
11
|
+
module Command
|
12
|
+
include Lab419::Tmux::Options::Api
|
13
|
+
|
14
|
+
def tmux cmd
|
15
|
+
if @options.dry_run
|
16
|
+
puts "tmux #{cmd}"
|
17
|
+
else
|
18
|
+
system "tmux #{cmd}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def tmux_current_window
|
23
|
+
window = [@options.session_name, tmux_current_window_number].join(":")
|
24
|
+
"-t #{window}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def tmux_current_window_command cmd, *args
|
28
|
+
args = args.compact
|
29
|
+
arguments = args.empty? ? "" : " #{args.join(" ")}"
|
30
|
+
tmux "#{cmd} #{tmux_current_window}#{arguments}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def tmux_current_window_number
|
34
|
+
@__tmux_current_window_number__ ||= 0
|
35
|
+
end
|
36
|
+
|
37
|
+
def tmux_current_window_number= new_val
|
38
|
+
@__tmux_current_window_number__ = new_val
|
39
|
+
end
|
40
|
+
|
41
|
+
def tmux_execute_window_commands
|
42
|
+
( @tmux_window_precommands || [] ).each do | blk |
|
43
|
+
blk.()
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def tmux_increase_current_window_number by=1
|
48
|
+
self.tmux_current_window_number += by
|
49
|
+
end
|
50
|
+
|
51
|
+
# tmux new-session -s $session_name -n console -d
|
52
|
+
def tmux_new_session params=nil
|
53
|
+
if has_tmux_session?
|
54
|
+
tmux "attach -t #{@options.session_name}"
|
55
|
+
exit 0
|
56
|
+
end
|
57
|
+
suffix = params ? " #{params}" : ""
|
58
|
+
session_name = @options.session_name
|
59
|
+
tmux "new-session -s #{session_name} -d#{suffix}"
|
60
|
+
return if @options.no_source_file || @options.tmux_source_file.nil?
|
61
|
+
tmux "source-file #{@options.tmux_source_file}"
|
62
|
+
tmux "set-window-option -g automatic-rename off"
|
63
|
+
tmux_project_home
|
64
|
+
at_exit do
|
65
|
+
tmux "attach -t #{session_name}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def tmux_new_window name=nil, dir=nil
|
70
|
+
tmux_increase_current_window_number
|
71
|
+
suffix = name ? %{ -n "#{name}"} : nil
|
72
|
+
tmux "new-window -t #{@options.session_name}#{suffix}"
|
73
|
+
tmux_set_window_options "automatic-rename off", "allow-rename off"
|
74
|
+
tmux_project_home dir
|
75
|
+
tmux_execute_window_commands
|
76
|
+
end
|
77
|
+
|
78
|
+
def tmux_open_vim options={}
|
79
|
+
dir = options.delete( :dir ){ "." }
|
80
|
+
tmux_send_keys "vi #{dir}"
|
81
|
+
options.each do | cmd, params |
|
82
|
+
command = ":#{[cmd,params].compact.join(" ")}"
|
83
|
+
tmux_send_keys command
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def tmux_open_irb options={}
|
88
|
+
lib = options.delete( :lib ){ "./lib" }
|
89
|
+
tmux_send_keys "irb -I#{lib}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def tmux_prefixed_command cmd, eol=true
|
93
|
+
tmux_send_keys [@options.cmd_prefix, cmd].mk_string, eol
|
94
|
+
end
|
95
|
+
|
96
|
+
def tmux_project_home dir=nil
|
97
|
+
dir = File.join @options.dir, dir if dir && %r{\A[^/]} === dir
|
98
|
+
tmux_send_keys "cd #{dir || @options.dir}"
|
99
|
+
end
|
100
|
+
|
101
|
+
def tmux_register_window_command noexec=false, &blk
|
102
|
+
blk.() unless noexec
|
103
|
+
@tmux_window_precommands ||= []
|
104
|
+
@tmux_window_precommands << blk
|
105
|
+
end
|
106
|
+
|
107
|
+
def tmux_send_keys keys, eol=true
|
108
|
+
suffix = eol ? " C-m" : nil
|
109
|
+
tmux_current_window_command "send-keys", %{"#{keys}"}, suffix
|
110
|
+
end
|
111
|
+
|
112
|
+
def tmux_set_window_option option
|
113
|
+
tmux_current_window_command "set-window-option", option
|
114
|
+
end
|
115
|
+
|
116
|
+
def tmux_set_window_options *options
|
117
|
+
options.each do | option |
|
118
|
+
tmux_set_window_option option
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'lab419/tmux/options/api'
|
3
|
+
include Lab419::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,20 @@
|
|
1
|
+
module Lab419
|
2
|
+
module Tmux
|
3
|
+
module Options
|
4
|
+
module Api
|
5
|
+
def has_tmux_session?
|
6
|
+
system "tmux has-session -t #{@options.session_name}"
|
7
|
+
end
|
8
|
+
def tmux_need_existing_dir
|
9
|
+
if !@options.dir
|
10
|
+
$stderr.puts "unable to determine session name"
|
11
|
+
exit -1
|
12
|
+
elsif !File.directory? @options.dir
|
13
|
+
$stderr.puts "no such directory #{@options.dir}"
|
14
|
+
exit -2
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lab419_tmux
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Dober
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.12
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.12
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cucumber
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.13.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.13.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aruba
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.5.3
|
69
|
+
description: A Gem that will give us helpers to dry up the creation of TMUX windows
|
70
|
+
and panes, adding some predefind layouts which are a good starting point for the
|
71
|
+
usage of this gem
|
72
|
+
email: robert.dober@gmail.com
|
73
|
+
executables:
|
74
|
+
- lab419_tmux
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- lib/lab419/tmux.rb
|
79
|
+
- lib/lab419/tmux/options/api.rb
|
80
|
+
- lib/lab419/tmux/options.rb
|
81
|
+
- lib/lab419/tmux/command.rb
|
82
|
+
- lib/lab419/tmux/version.rb
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- bin/lab419_tmux
|
86
|
+
homepage: https://github.com/RobertDober/lab419/tree/tmux-0.1.0/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.0.0
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Creating Tmux Windows And Panes Without Pains
|
110
|
+
test_files: []
|