termrc 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.termrc +2 -2
- data/README.md +8 -8
- data/lib/template/run.osascript +6 -6
- data/lib/template/termrc_base.template +3 -3
- data/lib/template/termrc_with_tabs.template +27 -0
- data/lib/termrc/builder.rb +76 -23
- data/lib/termrc/cli.rb +2 -1
- data/termrc.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d06e86ff71c380bb240d0d2f60a64cc71a3775f
|
4
|
+
data.tar.gz: 25e8812bffe0288f4a46e10a1b8941eec36cee9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c2b0a2c8053326bcd400d0e921494244fcab4e5e29e130fb5685c9e95d0c685c6587bd241973d4bf89160e5cfe16c48bcc19d9724e5d626436dd60ebd01e24f
|
7
|
+
data.tar.gz: b411d51211d9a4372568aff51c56dd7d4eaff1a47f9b7023db934408ea3d6024131193626310298e78c864565b39d6a682d4e7c710e1de5c8dd24331b2596104
|
data/.termrc
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
<img src="https://rawgithub.com/briangonzalez/termrc/master/images/osx.svg" width=25 style="margin-right: 10px"> termrc
|
3
2
|
======
|
4
3
|
Take your [iTerm2](http://www.iterm2.com/) environments with you wherever you go.
|
@@ -22,7 +21,6 @@ The `.termrc` file is a [YAML](http://en.wikipedia.org/wiki/YAML) file which sto
|
|
22
21
|
Place the `.termrc file` at your project's root, then call `termrc start`. Voila!
|
23
22
|
|
24
23
|
**Example .termrc**
|
25
|
-
|
26
24
|
```yaml
|
27
25
|
commands:
|
28
26
|
here: echo "Hello, here."
|
@@ -32,18 +30,20 @@ commands:
|
|
32
30
|
you: echo "Hello, you."
|
33
31
|
|
34
32
|
layout:
|
35
|
-
- [
|
36
|
-
- [
|
37
|
-
- [
|
33
|
+
- [ here, there ] # row 1, with 2 panes
|
34
|
+
- [ world ] # row 2, with 1 pane
|
35
|
+
- [ me, you ] # row 3, with 2 panes
|
38
36
|
```
|
39
37
|
|
40
38
|
**The Result**
|
41
|
-
|
42
39
|
A `.termrc` file is a YAML file which requires two keys: `commands` and a `layout`. Each item in `layout` corresponds to a row of panes in iTerm2. So, for instance, the example `.termrc` file above would produce a new iTerm2 window with the following commands running inside each pane:
|
43
40
|
|
44
41
|
<img src="https://rawgithub.com/briangonzalez/termrc/master/images/termrc-screen.png">
|
45
42
|
|
46
|
-
You can supply an optional third key, `root`, which indicates the root directory you'd like each command to be run inside of. Have a look at [this project's](https://github.com/briangonzalez/termrc/blob/master/.termrc)
|
43
|
+
You can supply an optional third key, `root`, which indicates the root directory you'd like each command to be run inside of. Have a look at [this project's](https://github.com/briangonzalez/termrc/blob/master/.termrc)`.termrc` file for an example.
|
44
|
+
|
45
|
+
** Tabs **
|
46
|
+
You can automate tabs by providing an array of arrays, each array denoting a new tab and the layout within it. See [this template file]() for an example.
|
47
47
|
|
48
48
|
CLI
|
49
49
|
---
|
@@ -66,4 +66,4 @@ Find me on [Twitter](http://twitter.com/brianmgonzalez).
|
|
66
66
|
Resources
|
67
67
|
---------
|
68
68
|
- [iTerm2 - Scripting with Applescript](https://code.google.com/p/iterm2/wiki/AppleScript)
|
69
|
-
- [iTerm2 - Working with panes](https://code.google.com/p/iterm2/issues/detail?id=559)
|
69
|
+
- [iTerm2 - Working with panes](https://code.google.com/p/iterm2/issues/detail?id=559)
|
data/lib/template/run.osascript
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
|
2
2
|
tell application "iTerm"
|
3
3
|
|
4
|
-
-- Create a new terminal window.
|
5
|
-
|
4
|
+
-- Create a new terminal window or tab.
|
5
|
+
[window_or_tab]
|
6
6
|
|
7
7
|
tell myterm
|
8
8
|
|
9
9
|
-- Create a new session.
|
10
|
-
|
10
|
+
[session]
|
11
11
|
|
12
12
|
-- Create rows.
|
13
13
|
[rows]
|
@@ -18,8 +18,8 @@ tell application "iTerm"
|
|
18
18
|
-- Create panes within each row.
|
19
19
|
[panes]
|
20
20
|
|
21
|
-
-- Terminate session
|
22
|
-
|
21
|
+
-- Terminate first or last session, which are unused.
|
22
|
+
[terminate_unused]
|
23
23
|
|
24
24
|
-- Sleep for a bit while we catch up.
|
25
25
|
[sleep]
|
@@ -30,6 +30,6 @@ tell application "iTerm"
|
|
30
30
|
end tell
|
31
31
|
|
32
32
|
-- Reposition window.
|
33
|
-
set the bounds of the first window to {10, 10, 600, 600}
|
33
|
+
-- set the bounds of the first window to {10, 10, 600, 600}
|
34
34
|
|
35
35
|
end tell
|
@@ -9,6 +9,6 @@ commands:
|
|
9
9
|
you: echo "Hello, you."
|
10
10
|
|
11
11
|
layout:
|
12
|
-
- [
|
13
|
-
- [
|
14
|
-
- [
|
12
|
+
- [ here, there ] # row 1, with 2 panes
|
13
|
+
- [ world ] # row 2, with 1 pane
|
14
|
+
- [ me, you ] # row 3, with 2 panes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
root:
|
2
|
+
~
|
3
|
+
|
4
|
+
commands:
|
5
|
+
here: echo "Hello, here."
|
6
|
+
there: echo "Hello, there."
|
7
|
+
world: echo "Hello, world."
|
8
|
+
me: echo "Hello, me."
|
9
|
+
you: echo "Hello, you."
|
10
|
+
|
11
|
+
layout:
|
12
|
+
- [
|
13
|
+
# Tab 1 **
|
14
|
+
[ here, there ] # row 1, with 2 panes
|
15
|
+
]
|
16
|
+
- [
|
17
|
+
# Tab 2 **
|
18
|
+
[ here, there ], # row 1, with 2 panes
|
19
|
+
[ world ], # row 2, with 1 pane
|
20
|
+
[ me, you ] # row 3, with 2 panes
|
21
|
+
]
|
22
|
+
- [
|
23
|
+
# Tab 3 **
|
24
|
+
[ here, there ], # row 1, with 2 panes
|
25
|
+
[ world ], # row 2, with 1 pane
|
26
|
+
[ me, you ] # row 3, with 2 panes
|
27
|
+
]
|
data/lib/termrc/builder.rb
CHANGED
@@ -10,25 +10,52 @@ module Termrc
|
|
10
10
|
TEMPLATE_FILE = File.join( File.expand_path('../..', __FILE__), 'template', 'run.osascript' )
|
11
11
|
TEMPLATE = File.read( TEMPLATE_FILE )
|
12
12
|
|
13
|
+
attr_accessor :layout
|
14
|
+
attr_accessor :commands
|
15
|
+
|
13
16
|
def initialize(yml)
|
14
17
|
@root = yml['root']
|
15
18
|
@commands = yml['commands']
|
16
19
|
@layout = yml['layout']
|
20
|
+
@cmd_index = 1
|
17
21
|
end
|
18
22
|
|
19
23
|
def run!
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
applescript_files.each do |f|
|
25
|
+
puts `/usr/bin/osascript #{f.path}`
|
26
|
+
f.unlink
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def applescript_files
|
31
|
+
if tabs?
|
32
|
+
return @layout.each_with_index.map{ |layout_array, index|
|
33
|
+
applescript_file(layout_array, index)
|
34
|
+
}
|
35
|
+
else
|
36
|
+
return [ applescript_file(@layout, 0) ]
|
37
|
+
end
|
23
38
|
end
|
24
39
|
|
25
|
-
def applescript_file
|
40
|
+
def applescript_file(layout_array, index)
|
26
41
|
t = TEMPLATE
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
42
|
+
|
43
|
+
if index > 0
|
44
|
+
# All other tabs.
|
45
|
+
t = t.gsub("[window_or_tab]", new_tab)
|
46
|
+
t = t.gsub("[session]", current_session)
|
47
|
+
t = t.gsub("[terminate_unused]", terminate_session('last'))
|
48
|
+
else
|
49
|
+
# First tab.
|
50
|
+
t = t.gsub("[window_or_tab]", new_window)
|
51
|
+
t = t.gsub("[session]", new_session)
|
52
|
+
t = t.gsub("[terminate_unused]", terminate_session)
|
53
|
+
end
|
54
|
+
|
55
|
+
t = t.gsub("[rows]", rows(layout_array))
|
56
|
+
t = t.gsub("[sleep]", rest)
|
57
|
+
t = t.gsub("[panes]", panes(layout_array))
|
58
|
+
t = t.gsub("[commands]", commands(layout_array))
|
32
59
|
|
33
60
|
file = Tempfile.new('termrc.osascript')
|
34
61
|
file.write(t)
|
@@ -36,15 +63,15 @@ module Termrc
|
|
36
63
|
file
|
37
64
|
end
|
38
65
|
|
39
|
-
def rows
|
40
|
-
Array.new( row_count, new_row ).join("\n")
|
66
|
+
def rows(layout_array)
|
67
|
+
Array.new( row_count(layout_array), new_row ).join("\n")
|
41
68
|
end
|
42
69
|
|
43
|
-
def panes
|
70
|
+
def panes(layout_array)
|
44
71
|
cmd = next_pane # back to the top
|
45
72
|
cmd = next_pane # back to the top
|
46
73
|
|
47
|
-
|
74
|
+
layout_array.each do |cmds|
|
48
75
|
cmd << Array.new( cmds.length - 1, new_column ).join("\n")
|
49
76
|
cmd << next_pane
|
50
77
|
cmd << "\n"
|
@@ -53,28 +80,31 @@ module Termrc
|
|
53
80
|
cmd
|
54
81
|
end
|
55
82
|
|
56
|
-
def commands
|
83
|
+
def commands(layout_array)
|
57
84
|
cmd = ""
|
58
85
|
|
59
|
-
|
60
|
-
@layout.each do |commands|
|
86
|
+
layout_array.each do |commands|
|
61
87
|
commands.each do |name|
|
62
|
-
cmd << execute_command(
|
63
|
-
|
88
|
+
cmd << execute_command( @cmd_index, @commands[name] )
|
89
|
+
@cmd_index += 1
|
64
90
|
end
|
65
91
|
end
|
66
92
|
|
67
93
|
cmd
|
68
94
|
end
|
69
95
|
|
70
|
-
def row_count
|
71
|
-
|
96
|
+
def row_count(layout_array)
|
97
|
+
layout_array.length
|
98
|
+
end
|
99
|
+
|
100
|
+
def tabs?
|
101
|
+
@layout[0].is_a?(Array) and @layout[0][0].is_a? Array
|
72
102
|
end
|
73
103
|
|
74
104
|
protected
|
75
105
|
|
76
|
-
def
|
77
|
-
"do shell script \"sleep #{
|
106
|
+
def rest(i=SLEEP_INTERVAL)
|
107
|
+
"do shell script \"sleep #{i}\" \n"
|
78
108
|
end
|
79
109
|
|
80
110
|
def new_row
|
@@ -89,6 +119,29 @@ module Termrc
|
|
89
119
|
keystroke("]", "command down")
|
90
120
|
end
|
91
121
|
|
122
|
+
def new_tab
|
123
|
+
[
|
124
|
+
keystroke("t", "command down"),
|
125
|
+
"set myterm to (current terminal)",
|
126
|
+
].join("\n")
|
127
|
+
end
|
128
|
+
|
129
|
+
def new_window
|
130
|
+
[ "set myterm to (make new terminal)" ].join("\n")
|
131
|
+
end
|
132
|
+
|
133
|
+
def new_session
|
134
|
+
"set mysession to (make new session at the end of sessions) "
|
135
|
+
end
|
136
|
+
|
137
|
+
def current_session
|
138
|
+
"set mysession to (current session) "
|
139
|
+
end
|
140
|
+
|
141
|
+
def terminate_session(which='first')
|
142
|
+
"terminate the #{which} session"
|
143
|
+
end
|
144
|
+
|
92
145
|
def execute_command(item, command)
|
93
146
|
command = command.gsub('"', '\\"')
|
94
147
|
command = command.gsub("'", "\\'")
|
@@ -98,7 +151,7 @@ module Termrc
|
|
98
151
|
|
99
152
|
def keystroke(key, using="")
|
100
153
|
cmd = "tell application \"System Events\" to keystroke \"#{key}\" "
|
101
|
-
cmd << "using #{using} \n" if using
|
154
|
+
cmd << "using {#{using}} \n" if using
|
102
155
|
cmd << "\n" if !using
|
103
156
|
cmd
|
104
157
|
end
|
data/lib/termrc/cli.rb
CHANGED
@@ -43,7 +43,8 @@ module Termrc
|
|
43
43
|
file = file || '.termrc'
|
44
44
|
raise Thor::Error.new "File '#{file}'' does not exist!" unless File.exist? file
|
45
45
|
|
46
|
-
say "Starting termrc file: '#{file}'", :yellow
|
46
|
+
say "Starting termrc file: '#{file}'.", :yellow
|
47
|
+
say "[ Please wait until fully launched! ]", :red
|
47
48
|
begin
|
48
49
|
Termrc::Base.new( File.expand_path(file) )
|
49
50
|
rescue Exception => e
|
data/termrc.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
10
10
|
gem.executables << 'termrc'
|
11
11
|
gem.name = "termrc"
|
12
|
-
gem.version = '0.
|
12
|
+
gem.version = '0.2.0'
|
13
13
|
gem.license = 'MIT'
|
14
14
|
|
15
15
|
gem.add_runtime_dependency 'thor', '~> 0.18.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: termrc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Gonzalez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- bin/termrc
|
40
40
|
- lib/template/run.osascript
|
41
41
|
- lib/template/termrc_base.template
|
42
|
+
- lib/template/termrc_with_tabs.template
|
42
43
|
- lib/termrc.rb
|
43
44
|
- lib/termrc/base.rb
|
44
45
|
- lib/termrc/builder.rb
|