termrc 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +0 -0
- data/.termrc +11 -0
- data/README.md +57 -0
- data/Rakefile +36 -0
- data/bin/termrc +11 -0
- data/lib/template/run.osascript +35 -0
- data/lib/template/termrc_base.template +14 -0
- data/lib/termrc/base.rb +18 -0
- data/lib/termrc/builder.rb +108 -0
- data/lib/termrc/cli.rb +58 -0
- data/lib/termrc.rb +6 -0
- data/termrc.gemspec +16 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1fe6b6ea69f9c28c5440f07d8c3693125e5cd65c
|
4
|
+
data.tar.gz: 98a1ac37eeda6e058883069d2c20a524bdbdee2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0baba665dcbac8ca1eb5fb1d7b5308000a43a801a2775ca46a694a106c70c5cef8ab1469b3c401b6830015b864ec5772c0d201b5edd660ff713b8af2e208408f
|
7
|
+
data.tar.gz: 56d0210faf7b921f9c9cf8ae18e8aa1d733a7c5245ee50a76a9e6d0b52123aaee1c6a5da1f6e921abdd0148deccc0d201c58ab54eab29977817f8a9e5f9f53b0
|
data/.gitignore
ADDED
File without changes
|
data/.termrc
ADDED
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
<img src="https://rawgithub.com/briangonzalez/termrc/master/images/osx.svg" width=25 style="margin-right: 10px"> termrc
|
3
|
+
======
|
4
|
+
Take your iTerm2 environments with you wherever you go.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
Termrc allows you to store information about your project's environment for a given project in a small YAML file called a `.termrc` file. Restoring your project's environment is as simple as calling `termrc start`. Enjoy.
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
```bash
|
13
|
+
$ gem install termrc
|
14
|
+
$ termrc create
|
15
|
+
$ termrc start
|
16
|
+
```
|
17
|
+
|
18
|
+
.termrc file
|
19
|
+
----------
|
20
|
+
The `.termrc` file is a [YAML](http://en.wikipedia.org/wiki/YAML) file which stores information about your project's environment. An environment, in this context, is an iTerm2 window with various panes, each with a different default command that is run when the pane opens. The `layout` dictates what your window looks like, while `commands` gives you a set of commands you can call for each pane.
|
21
|
+
|
22
|
+
**Example .termrc**
|
23
|
+
|
24
|
+
```yaml
|
25
|
+
commands:
|
26
|
+
here: echo "Hello, here."
|
27
|
+
there: echo "Hello, there."
|
28
|
+
world: echo "Hello, world."
|
29
|
+
me: echo "Hello, me."
|
30
|
+
you: echo "Hello, you."
|
31
|
+
|
32
|
+
layout:
|
33
|
+
- [ 'here', 'there' ] # row 1, with 2 panes
|
34
|
+
- [ 'world' ] # row 2, with 1 pane
|
35
|
+
- [ 'me', 'you' ] # row 3, with 2 panes
|
36
|
+
```
|
37
|
+
|
38
|
+
**The Result**
|
39
|
+
|
40
|
+
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:
|
41
|
+
|
42
|
+
<img src="https://rawgithub.com/briangonzalez/termrc/master/images/termrc-screen.png">
|
43
|
+
|
44
|
+
You can supply an optional third key, `root`, which indicates the root directory you'd like each command to be run inside of.
|
45
|
+
|
46
|
+
License
|
47
|
+
--------
|
48
|
+
Released under the MIT License.
|
49
|
+
|
50
|
+
Questions?
|
51
|
+
----------
|
52
|
+
Find me on [Twitter](http://twitter.com/brianmgonzalez).
|
53
|
+
|
54
|
+
Resources
|
55
|
+
---------
|
56
|
+
- [iTerm2 - Scripting with Applescript](https://code.google.com/p/iterm2/wiki/AppleScript)
|
57
|
+
- [iTerm2 - Working with panes](https://code.google.com/p/iterm2/issues/detail?id=559)
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
namespace :gem do
|
2
|
+
|
3
|
+
desc "build"
|
4
|
+
task :build do
|
5
|
+
puts %x[rm -rf *.gem]
|
6
|
+
puts %x[gem build *.gemspec]
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "install"
|
10
|
+
task :install do
|
11
|
+
puts %x[gem install *.gem]
|
12
|
+
puts %x[rm -rf *.gem]
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "release"
|
16
|
+
task :release do
|
17
|
+
gems = Dir.glob("*.gem").length
|
18
|
+
puts gems
|
19
|
+
raise "0 or > 1 gem in directory; aborting!" if gems != 1
|
20
|
+
puts %x[gem push *.gem]
|
21
|
+
puts %x[rm -rf *.gem]
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "build & install"
|
25
|
+
task :build_and_install do
|
26
|
+
Rake::Task["gem:build"].invoke
|
27
|
+
Rake::Task["gem:install"].invoke
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "build & release"
|
31
|
+
task :build_and_release do
|
32
|
+
Rake::Task["gem:build"].invoke
|
33
|
+
Rake::Task["gem:release"].invoke
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/bin/termrc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
tell application "iTerm"
|
3
|
+
|
4
|
+
-- Create a new terminal window.
|
5
|
+
set myterm to (make new terminal)
|
6
|
+
|
7
|
+
tell myterm
|
8
|
+
|
9
|
+
-- Create a new session.
|
10
|
+
set mysession to (make new session at the end of sessions)
|
11
|
+
|
12
|
+
-- Create rows.
|
13
|
+
[rows]
|
14
|
+
|
15
|
+
-- Sleep for a bit while we catch up.
|
16
|
+
[sleep]
|
17
|
+
|
18
|
+
-- Create panes within each row.
|
19
|
+
[panes]
|
20
|
+
|
21
|
+
-- Terminate session 1, which is unused.
|
22
|
+
terminate the first session
|
23
|
+
|
24
|
+
-- Sleep for a bit while we catch up.
|
25
|
+
[sleep]
|
26
|
+
|
27
|
+
-- Create all commands for a given pane (item).
|
28
|
+
[commands]
|
29
|
+
|
30
|
+
end tell
|
31
|
+
|
32
|
+
-- Reposition window.
|
33
|
+
set the bounds of the first window to {10, 10, 600, 600}
|
34
|
+
|
35
|
+
end tell
|
@@ -0,0 +1,14 @@
|
|
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
|
+
- [ 'here', 'there' ] # row 1, with 2 panes
|
13
|
+
- [ 'world' ] # row 2, with 1 pane
|
14
|
+
- [ 'me', 'you' ] # row 3, with 2 panes
|
data/lib/termrc/base.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
require 'yaml'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
module Termrc
|
6
|
+
|
7
|
+
class Builder
|
8
|
+
|
9
|
+
SLEEP_INTERVAL = 1
|
10
|
+
TEMPLATE_FILE = File.join( File.expand_path('../..', __FILE__), 'template', 'run.osascript' )
|
11
|
+
TEMPLATE = File.read( TEMPLATE_FILE )
|
12
|
+
|
13
|
+
def initialize(yml)
|
14
|
+
@root = yml['root']
|
15
|
+
@commands = yml['commands']
|
16
|
+
@layout = yml['layout']
|
17
|
+
end
|
18
|
+
|
19
|
+
def run!
|
20
|
+
f = applescript_file
|
21
|
+
puts `/usr/bin/osascript #{f.path}`
|
22
|
+
f.unlink
|
23
|
+
end
|
24
|
+
|
25
|
+
def applescript_file
|
26
|
+
t = TEMPLATE
|
27
|
+
t = t.gsub("[rows]", rows)
|
28
|
+
t = t.gsub("[sleep]", sleep)
|
29
|
+
t = t.gsub("[panes]", panes)
|
30
|
+
t = t.gsub("[commands]", commands)
|
31
|
+
t
|
32
|
+
|
33
|
+
file = Tempfile.new('termrc.osascript')
|
34
|
+
file.write(t)
|
35
|
+
file.close
|
36
|
+
file
|
37
|
+
end
|
38
|
+
|
39
|
+
def rows
|
40
|
+
Array.new( row_count, new_row ).join("\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
def panes
|
44
|
+
cmd = next_pane # back to the top
|
45
|
+
cmd = next_pane # back to the top
|
46
|
+
|
47
|
+
@layout.each do |cmds|
|
48
|
+
cmd << Array.new( cmds.length - 1, new_column ).join("\n")
|
49
|
+
cmd << next_pane
|
50
|
+
cmd << "\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
cmd
|
54
|
+
end
|
55
|
+
|
56
|
+
def commands
|
57
|
+
cmd = ""
|
58
|
+
|
59
|
+
index = 1
|
60
|
+
@layout.each do |commands|
|
61
|
+
commands.each do |name|
|
62
|
+
cmd << execute_command(index, @commands[name] )
|
63
|
+
index += 1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
cmd
|
68
|
+
end
|
69
|
+
|
70
|
+
def row_count
|
71
|
+
@row_count ||= @layout.length
|
72
|
+
end
|
73
|
+
|
74
|
+
protected
|
75
|
+
|
76
|
+
def sleep
|
77
|
+
"do shell script \"sleep #{SLEEP_INTERVAL}\" \n"
|
78
|
+
end
|
79
|
+
|
80
|
+
def new_row
|
81
|
+
keystroke("D", "command down")
|
82
|
+
end
|
83
|
+
|
84
|
+
def new_column
|
85
|
+
keystroke("d", "command down")
|
86
|
+
end
|
87
|
+
|
88
|
+
def next_pane
|
89
|
+
keystroke("]", "command down")
|
90
|
+
end
|
91
|
+
|
92
|
+
def execute_command(item, command)
|
93
|
+
command = command.gsub('"', '\\"')
|
94
|
+
command = command.gsub("'", "\\'")
|
95
|
+
command = "cd #{@root} && " + command if @root
|
96
|
+
"tell item #{item} of sessions to write text \"#{command}\" \n"
|
97
|
+
end
|
98
|
+
|
99
|
+
def keystroke(key, using="")
|
100
|
+
cmd = "tell application \"System Events\" to keystroke \"#{key}\" "
|
101
|
+
cmd << "using #{using} \n" if using
|
102
|
+
cmd << "\n" if !using
|
103
|
+
cmd
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
data/lib/termrc/cli.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Termrc
|
5
|
+
|
6
|
+
TERMRC_TEMPLATE = File.join( File.expand_path('../..', __FILE__), 'template', 'termrc_base.template' )
|
7
|
+
|
8
|
+
class Cli < Thor
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
map 'c' => :create
|
12
|
+
map 'l' => :list
|
13
|
+
map 's' => :start
|
14
|
+
|
15
|
+
desc 'create', 'Create termrc file (Shortcut: c)'
|
16
|
+
def create
|
17
|
+
|
18
|
+
if File.exist? '.termrc'
|
19
|
+
raise Thor::Error.new "Error: '.termrc' already exists!"
|
20
|
+
else
|
21
|
+
say "Creating .termrc file..", :yellow
|
22
|
+
FileUtils.cp TERMRC_TEMPLATE, '.termrc'
|
23
|
+
|
24
|
+
say "Success! \n\n", :yellow
|
25
|
+
|
26
|
+
say "Now run your new termrc file by calling `termrc start`", :blue
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'list', 'List termrc files (Shortcut: l, Options: --folder=<folder>)'
|
31
|
+
method_option :folder, :type => :string, :required => false
|
32
|
+
def list
|
33
|
+
folder = options[:folder] || '.'
|
34
|
+
say "Looking for termrc files in '#{folder}':", :yellow
|
35
|
+
|
36
|
+
a = `find #{folder} | grep -w \.termrc$`
|
37
|
+
say a
|
38
|
+
|
39
|
+
say "None found.", :red if a.length < 1
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'start', 'Start termrc file (Shortcut: s, Options: --file=<termc file>)'
|
43
|
+
method_option :file, :type => :string, :required => false
|
44
|
+
def start
|
45
|
+
file = options[:file] || '.termrc'
|
46
|
+
raise Thor::Error.new "File '#{file}'' does not exist!" unless File.exist? file
|
47
|
+
|
48
|
+
say "Starting termrc file: '#{file}'", :yellow
|
49
|
+
begin
|
50
|
+
Termrc::Base.new( File.expand_path(file) )
|
51
|
+
rescue Exception => e
|
52
|
+
say "\nError while starting termrc file:", :red
|
53
|
+
puts e
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
data/lib/termrc.rb
ADDED
data/termrc.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.authors = ["Brian Gonzalez"]
|
3
|
+
gem.email = ["me@briangonzalez.org"]
|
4
|
+
gem.description = "Take your iTerm2 environments with you wherever you go."
|
5
|
+
gem.summary = "Take your iTerm2 environments with you wherever you go."
|
6
|
+
gem.homepage = "https://github.com/briangonzalez/termrc"
|
7
|
+
|
8
|
+
gem.files = `git ls-files`.split($\).reject{|f| f =~ /^images/ } # Exclude images
|
9
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
10
|
+
gem.executables << 'termrc'
|
11
|
+
gem.name = "termrc"
|
12
|
+
gem.version = '0.1.0'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.add_runtime_dependency 'thor', '~> 0.18.0'
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: termrc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Gonzalez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.18.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.18.0
|
27
|
+
description: Take your iTerm2 environments with you wherever you go.
|
28
|
+
email:
|
29
|
+
- me@briangonzalez.org
|
30
|
+
executables:
|
31
|
+
- termrc
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- .termrc
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/termrc
|
40
|
+
- lib/template/run.osascript
|
41
|
+
- lib/template/termrc_base.template
|
42
|
+
- lib/termrc.rb
|
43
|
+
- lib/termrc/base.rb
|
44
|
+
- lib/termrc/builder.rb
|
45
|
+
- lib/termrc/cli.rb
|
46
|
+
- termrc.gemspec
|
47
|
+
homepage: https://github.com/briangonzalez/termrc
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.0.3
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Take your iTerm2 environments with you wherever you go.
|
71
|
+
test_files: []
|