paulcoyle-termsaver 0.1.2
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.
- data/COPYING +18 -0
- data/README.markdown +52 -0
- data/Rakefile +42 -0
- data/TODO +3 -0
- data/VERSION.yml +4 -0
- data/bin/termsaver +7 -0
- data/lib/termsaver.rb +3 -0
- data/lib/termsaver/application.rb +62 -0
- data/lib/termsaver/options.rb +27 -0
- data/lib/termsaver/types.rb +37 -0
- data/test/colour_test.rb +8 -0
- data/test/position_test.rb +8 -0
- data/test/state_test.rb +7 -0
- data/test/test_helper.rb +3 -0
- metadata +87 -0
data/COPYING
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2009 Paul Coyle
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
TermSaver
|
2
|
+
=========
|
3
|
+
TermSaver is just a simple library built around the Appscript library to
|
4
|
+
automate saving the geometry of Mac OS' Terminal.app windows and provide a way
|
5
|
+
to rebuild them and provide them with initial commands on their creation.
|
6
|
+
|
7
|
+
Usage
|
8
|
+
-----
|
9
|
+
Arrange your terminal windows however you like. Use the `save` command to
|
10
|
+
generate a file with the saved window states.
|
11
|
+
|
12
|
+
termsaver -s saved_state.yml
|
13
|
+
|
14
|
+
or
|
15
|
+
|
16
|
+
termsaver --save saved_state.yml
|
17
|
+
|
18
|
+
You can then edit this file and enter shell commands in the "command" property
|
19
|
+
of each `State`. These commands will be executed once the terminal windows are
|
20
|
+
re-instated.
|
21
|
+
|
22
|
+
Example:
|
23
|
+
|
24
|
+
---
|
25
|
+
- !ruby/object:TermSaver::State
|
26
|
+
background_color: !ruby/object:TermSaver::Colour
|
27
|
+
b: 53971
|
28
|
+
g: 65535
|
29
|
+
r: 48805
|
30
|
+
command: "echo 'Sugarnipples.'"
|
31
|
+
number_of_columns: 80
|
32
|
+
number_of_rows: 24
|
33
|
+
position: !ruby/object:TermSaver::Position
|
34
|
+
x: -614
|
35
|
+
y: 17
|
36
|
+
|
37
|
+
To load in your saved states, use the `load` command.
|
38
|
+
|
39
|
+
termsaver -l saved_state.yml
|
40
|
+
|
41
|
+
or
|
42
|
+
|
43
|
+
termsaver --load saved_state.yml
|
44
|
+
|
45
|
+
Notes & Limitations
|
46
|
+
-------------------
|
47
|
+
If you do not already have an instance of Terminal.app running, then it seems
|
48
|
+
that an additional Terminal window will be opened. Currently there is nothing
|
49
|
+
to handle this.
|
50
|
+
|
51
|
+
Currently, the only properties of windows being stored are: position, background
|
52
|
+
colour, number of rows and number of columns.
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
|
3
|
+
task :default => :test
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.pattern = 'test/*_test.rb'
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Writes out the current Terminal.app window states to a file.'
|
11
|
+
task :save, [:file_path] do |t, args|
|
12
|
+
args.with_defaults(:file_path => 'term_settings.yml')
|
13
|
+
TermSaver::save(args[:file_path])
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Loads a windows states file created with the save task and build out the windows.'
|
17
|
+
task :load, [:file_path] do |t, args|
|
18
|
+
args.with_defaults(:file_path => 'term_settings.yml')
|
19
|
+
TermSaver::load(args[:file_path])
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'jeweler'
|
24
|
+
Jeweler::Tasks.new do |s|
|
25
|
+
s.name = "termsaver"
|
26
|
+
s.summary = "Saves and restores the position, colour and runs inital commands on Mac OS X Terminal.app windows."
|
27
|
+
s.email = "paul@paulcoyle.com"
|
28
|
+
s.homepage = "http://github.com/paulcoyle/termsaver"
|
29
|
+
s.description = <<-EOF
|
30
|
+
TermSaver is just a simple library built around the Appscript library to
|
31
|
+
automate saving the geometry of Mac OS' Terminal.app windows and provide
|
32
|
+
a way to rebuild them and provide them with initial commands on their
|
33
|
+
creation.
|
34
|
+
EOF
|
35
|
+
s.authors = ["Paul Coyle"]
|
36
|
+
s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
|
37
|
+
s.add_dependency('activesupport', '>= 2.2.2')
|
38
|
+
s.add_dependency('rb-appscript', '>= 0.5.1')
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
42
|
+
end
|
data/TODO
ADDED
data/VERSION.yml
ADDED
data/bin/termsaver
ADDED
data/lib/termsaver.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'appscript'
|
3
|
+
|
4
|
+
class TermSaver
|
5
|
+
class Application
|
6
|
+
class << self
|
7
|
+
include Appscript
|
8
|
+
|
9
|
+
def run!(*args)
|
10
|
+
options = TermSaver::Options.new(args)
|
11
|
+
unless options[:mode].nil?
|
12
|
+
self.send(options[:mode], options[:file_path])
|
13
|
+
else
|
14
|
+
raise StandardError.new('Must have a mode flag of either -s or -l to run.')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Saves all the states from Terminal.app to the file_path provided.
|
19
|
+
def save(file_path)
|
20
|
+
@states = []
|
21
|
+
terminal = get_app
|
22
|
+
(1..terminal.windows.count).each { |window_id| @states << save_state(terminal.windows[window_id]) }
|
23
|
+
File.open(file_path, 'w') do |file|
|
24
|
+
YAML::dump(@states, file)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Expects a path to a file that is a YAML serialization of State objects.
|
29
|
+
def load(file_path)
|
30
|
+
File.open(file_path) { |file| @states = YAML::load(file) }
|
31
|
+
terminal = get_app
|
32
|
+
@states.each { |state| load_state(state, terminal) }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Saves the state of a window to a State object.
|
36
|
+
def save_state(window)
|
37
|
+
TermSaver::Type::State.new do |s|
|
38
|
+
s.position = TermSaver::Type::Position.new(*window.position.get)
|
39
|
+
s.background_color = TermSaver::Type::Colour.new(*window.background_color.get)
|
40
|
+
s.number_of_columns = window.number_of_columns.get
|
41
|
+
s.number_of_rows = window.number_of_rows.get
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Recreates the given state.
|
46
|
+
def load_state(state, terminal = nil)
|
47
|
+
terminal ||= get_app
|
48
|
+
terminal.do_script(state.command)
|
49
|
+
window = terminal.windows[1]
|
50
|
+
window.background_color.set(state.background_color.to_appscript_format)
|
51
|
+
window.position.set(state.position.to_appscript_format)
|
52
|
+
window.number_of_columns.set(state.number_of_columns)
|
53
|
+
window.number_of_rows.set(state.number_of_rows)
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
def get_app
|
58
|
+
app('Terminal.app')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class TermSaver
|
4
|
+
class Options < Hash
|
5
|
+
def initialize(args)
|
6
|
+
super()
|
7
|
+
|
8
|
+
self[:file_path] = 'termsaver_save.yml'
|
9
|
+
|
10
|
+
opts = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: termsaver [options]"
|
12
|
+
|
13
|
+
opts.on('-s', '--save [FILEPATH]', String, 'Save the Terminal.app window states to the file specified. (default: termsaver_save.yml)') do |save|
|
14
|
+
self[:mode] = :save
|
15
|
+
self[:file_path] = save unless save.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on('-l', '--load [FILEPATH]', String, 'Loads saved windows states from the file specified. (default: termsaver_save.yml)') do |load|
|
19
|
+
self[:mode] = :load
|
20
|
+
self[:file_path] = load unless load.nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.parse!(args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class TermSaver
|
2
|
+
class Type
|
3
|
+
class State
|
4
|
+
attr_accessor :position, :background_color, :number_of_columns,
|
5
|
+
:number_of_rows, :command
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
self.command = ''
|
9
|
+
yield self if block_given?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Position
|
14
|
+
attr_accessor :x, :y
|
15
|
+
|
16
|
+
def initialize(x = 0, y = 0)
|
17
|
+
self.x, self.y = x, y
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_appscript_format
|
21
|
+
[self.x, self.y]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Colour
|
26
|
+
attr_accessor :r, :g, :b
|
27
|
+
|
28
|
+
def initialize(r = 0, g = 0, b = 0)
|
29
|
+
self.r, self.g, self.b = r, g, b
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_appscript_format
|
33
|
+
[self.r, self.g, self.b]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/test/colour_test.rb
ADDED
data/test/state_test.rb
ADDED
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paulcoyle-termsaver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Coyle
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-09 00:00:00 -07:00
|
13
|
+
default_executable: termsaver
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.2.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rb-appscript
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.1
|
34
|
+
version:
|
35
|
+
description: TermSaver is just a simple library built around the Appscript library to automate saving the geometry of Mac OS' Terminal.app windows and provide a way to rebuild them and provide them with initial commands on their creation.
|
36
|
+
email: paul@paulcoyle.com
|
37
|
+
executables:
|
38
|
+
- termsaver
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.markdown
|
43
|
+
files:
|
44
|
+
- COPYING
|
45
|
+
- Rakefile
|
46
|
+
- README.markdown
|
47
|
+
- TODO
|
48
|
+
- VERSION.yml
|
49
|
+
- bin/termsaver
|
50
|
+
- lib/termsaver
|
51
|
+
- lib/termsaver/application.rb
|
52
|
+
- lib/termsaver/options.rb
|
53
|
+
- lib/termsaver/types.rb
|
54
|
+
- lib/termsaver.rb
|
55
|
+
- test/colour_test.rb
|
56
|
+
- test/position_test.rb
|
57
|
+
- test/state_test.rb
|
58
|
+
- test/test_helper.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/paulcoyle/termsaver
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --inline-source
|
64
|
+
- --charset=UTF-8
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 2
|
85
|
+
summary: Saves and restores the position, colour and runs inital commands on Mac OS X Terminal.app windows.
|
86
|
+
test_files: []
|
87
|
+
|