ruby-screen 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +20 -0
  3. data/Manifest.txt +44 -0
  4. data/README.textile +226 -0
  5. data/README.txt +1 -0
  6. data/Rakefile +4 -0
  7. data/bin/ruby-screen +5 -0
  8. data/config/hoe.rb +71 -0
  9. data/config/requirements.rb +17 -0
  10. data/lib/ruby_screen.rb +14 -0
  11. data/lib/ruby_screen/configuration/description.rb +60 -0
  12. data/lib/ruby_screen/configuration/generator.rb +54 -0
  13. data/lib/ruby_screen/configuration/parser.rb +35 -0
  14. data/lib/ruby_screen/configuration/parser/block_processor.rb +43 -0
  15. data/lib/ruby_screen/configuration/parser/iterator.rb +31 -0
  16. data/lib/ruby_screen/configuration/parser/nesting_hash.rb +37 -0
  17. data/lib/ruby_screen/executer.rb +26 -0
  18. data/lib/ruby_screen/preferences_loader.rb +26 -0
  19. data/lib/ruby_screen/version.rb +9 -0
  20. data/log/debug.log +0 -0
  21. data/script/destroy +14 -0
  22. data/script/generate +14 -0
  23. data/script/txt2html +74 -0
  24. data/setup.rb +1585 -0
  25. data/spec/configuration/description_spec.rb +93 -0
  26. data/spec/configuration/generator_spec.rb +49 -0
  27. data/spec/configuration/parser/block_processor_spec.rb +46 -0
  28. data/spec/configuration/parser/iterator_spec.rb +35 -0
  29. data/spec/configuration/parser/nesting_hash_spec.rb +59 -0
  30. data/spec/configuration/parser_spec.rb +73 -0
  31. data/spec/executer_spec.rb +63 -0
  32. data/spec/preferences_loader_spec.rb +46 -0
  33. data/spec/ruby_screen_spec.rb +33 -0
  34. data/spec/spec.opts +1 -0
  35. data/spec/spec_helper.rb +9 -0
  36. data/tasks/deployment.rake +34 -0
  37. data/tasks/environment.rake +7 -0
  38. data/tasks/rspec.rake +21 -0
  39. data/tasks/website.rake +17 -0
  40. data/website/index.html +289 -0
  41. data/website/index.txt +226 -0
  42. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  43. data/website/stylesheets/screen.css +138 -0
  44. data/website/template.rhtml +48 -0
  45. metadata +111 -0
@@ -0,0 +1,3 @@
1
+ == 0.0.9 2008-06-04
2
+
3
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.textile
5
+ README.txt
6
+ Rakefile
7
+ bin/ruby-screen
8
+ config/hoe.rb
9
+ config/requirements.rb
10
+ lib/ruby_screen.rb
11
+ lib/ruby_screen/version.rb
12
+ lib/ruby_screen/preferences_loader.rb
13
+ lib/ruby_screen/executer.rb
14
+ lib/ruby_screen/configuration/description.rb
15
+ lib/ruby_screen/configuration/generator.rb
16
+ lib/ruby_screen/configuration/parser.rb
17
+ lib/ruby_screen/configuration/parser/block_processor.rb
18
+ lib/ruby_screen/configuration/parser/nesting_hash.rb
19
+ lib/ruby_screen/configuration/parser/iterator.rb
20
+ log/debug.log
21
+ script/destroy
22
+ script/generate
23
+ script/txt2html
24
+ setup.rb
25
+ spec/ruby_screen_spec.rb
26
+ spec/preferences_loader_spec.rb
27
+ spec/executer_spec.rb
28
+ spec/spec.opts
29
+ spec/spec_helper.rb
30
+ spec/configuration/description_spec.rb
31
+ spec/configuration/parser_spec.rb
32
+ spec/configuration/generator_spec.rb
33
+ spec/configuration/parser/block_processor_spec.rb
34
+ spec/configuration/parser/iterator_spec.rb
35
+ spec/configuration/parser/nesting_hash_spec.rb
36
+ tasks/deployment.rake
37
+ tasks/environment.rake
38
+ tasks/rspec.rake
39
+ tasks/website.rake
40
+ website/index.html
41
+ website/index.txt
42
+ website/javascripts/rounded_corners_lite.inc.js
43
+ website/stylesheets/screen.css
44
+ website/template.rhtml
@@ -0,0 +1,226 @@
1
+ h1. RubyScreen
2
+
3
+ RubyScreen is a utility for managing and launching GNU Screen configurations. Though written in Ruby and requiring a valid Ruby installation, it should be useful for a developer in any language. If you often find yourself opening up the same multiple windows and running various commands, or juggling multiple similar Screen configurations with various window setups, this may help.
4
+
5
+ Usage is best described through a few examples, which are followed by detailed information on the available elements in the configuration file.
6
+
7
+ h2. Installation
8
+
9
+ RubyScreen is packaged as a Ruby Gem, and requires a valid installation of Ruby along with the RubyGems package manager. Rather than document that process, you're likely to find more helpful instructions for installing those two components "here":http://www.rubyonrails.org/down at the Ruby on Rails installation page.
10
+
11
+ Once you have gems, you're just a command away:
12
+
13
+ gem install ruby-screen
14
+
15
+ On non-Windows systems, you may need to use *sudo* to elevate you privileges.
16
+
17
+ To verify installation, try *ruby-screen* at your command prompt. You should see a helpful message about your lack of configuration file. You can build your own configuration file after reading the documentation below.
18
+
19
+ h2. Examples
20
+
21
+ RubyScreen consists of a "YAML":http://www.yaml.org/ configuration file and a command line utility. The configuration file must be located in your home directory and named _.ruby-screen.yml_. The simplest example:
22
+
23
+ <pre><code>
24
+ startup_message: off
25
+ defscrollback: 5000
26
+ </pre></code>
27
+
28
+ The command for launching RubyScreen is *ruby-screen*. It will load your YAML configuration file and launch Screen with the appropriate options. With the configuration file above, you'll have no splash screen and a 5000 line scroll buffer. Not exactly revolutionary.
29
+
30
+ Let's say you're a web developer working on a cool new project. You're using your favorite text editor, watching some logs, keeping a window open for miscellaneous tasks. Your configuration file would look something like this:
31
+
32
+ <pre><code>
33
+ startup_message: off
34
+ defscrollback: 5000
35
+
36
+ cool_site:
37
+ working_directory: ~/web_projects/cool_site
38
+ windows:
39
+ -
40
+ title: Editor
41
+ command: vim .
42
+ -
43
+ title: Misc
44
+ -
45
+ title: Logs
46
+ number: 9
47
+ command: tail -f /var/log/web_server.log
48
+ </pre></code>
49
+
50
+ Now you still have your generic configuration, along with an additional configuration for your cool project. Running *ruby-screen cool_site* will move into your projects' directory and start a text editor, a window with a fresh command line, and a window tailing your server log. The first two windows take whatever number Screen assigns to them (0 and 1 in this case), while the log window will always be assigned to number 9.
51
+
52
+ That's great, but you are working on more than just that one cool project. You have multiple sites located in <notextile>~</notextile>_/web_projects_, and they all have they all have similar needs: an editor, a terminal, and a log viewer.
53
+
54
+ <pre><code>
55
+ startup_message: off
56
+ defscrollback: 5000
57
+
58
+ web_work:
59
+ working_directory: ~/web_projects
60
+ windows:
61
+ -
62
+ title: Editor
63
+ command: vim .
64
+ -
65
+ title: Misc
66
+ -
67
+ title: Logs
68
+ number: 9
69
+ command: tail -f /var/log/web_server.log
70
+ </pre></code>
71
+
72
+ This configuration is identical to the last, except that it is a bit more generic. The configuration named _cool_site_ is now _web_work_, and the *working_directory* now points to your generic projects directory. When you use the *ruby-screen* command line utility, the first argument is usually going to refer to the name of one of your nested configurations, with any additional arguments being tacked on as directories relative to the *working_directory* specified in that configuration.
73
+
74
+ If you had a couple of web projects you are working on, like <notextile>~</notextile>_/web_projects/cool_project_, or <notextile>~</notextile>_/web_projects/legacy_work_, those specific projects can be launched using the generic _web_work_ configuration by typing *ruby-screen web_work cool_project* and *ruby-screen web_work legacy_work* respectively. Any new projects added to <notextile>~</notextile>_/web_projects_ can be launched by name through the *web_work* configuration.
75
+
76
+ Finally, let's return to your cool site. You have added some fancy new chat functionality to it, but that requires the chat server to be running during every development session. Aside from the chat server, it's the same as all of your other web projects.
77
+
78
+ <pre><code>
79
+ startup_message: off
80
+ defscrollback: 5000
81
+
82
+ web_work:
83
+ working_directory: ~/web_projects
84
+ windows:
85
+ -
86
+ title: Editor
87
+ command: vim .
88
+ -
89
+ title: Misc
90
+ -
91
+ title: Logs
92
+ number: 9
93
+ command: tail -f /var/log/web_server.log
94
+
95
+ cool_site:
96
+ relative_directory: cool_site
97
+ windows:
98
+ -
99
+ title: Chat Server
100
+ command: /bin/my_awesome_chat_server
101
+ </pre></code>
102
+
103
+ You've added on to the previous example and added a nested configuration, called _cool_site_. It's under _web_work_, and inherits all the Customizations and Windows defined above it, while defining a new window that will launch your chat server. This nested configuration can be launched from the command line with *ruby-screen cool_site*.
104
+
105
+ h2. The Configuration File
106
+
107
+ RubyScreen looks for a file in your home directory named *.ruby-screen.yml*. It must be a valid YAML file. It can contain multiple elements that will be translated into a Screen-compatible plain text configuration file, depending on the command line arguments that are passed in when RubyScreen is launched.
108
+
109
+ h3. Customizations
110
+
111
+ The simplest element, customizations consist of simple key/value pairs. Valid customizations can be found in the "Customization" section of the Screen manpage.
112
+
113
+ <pre><code>
114
+ startup_message: off
115
+ defscrollback: 5000
116
+ </pre></code>
117
+
118
+ This will result in a Screen configuration without the welcoming splash page, with a 5000 line scroll buffer.
119
+
120
+ (YAML veterans may wonder that the 'off' value need not be quoted. Pay no attention to the man behind the curtain. It just doesn't.)
121
+
122
+ h3. Windows
123
+
124
+ Windows in Screen are somewhat analogous to tabs in a browser. You can use window definitions to specify the windows you want open at launch. You can optionally title and number them, as well as giving them an initial command to execute at launch.
125
+
126
+ <pre><code>
127
+ windows:
128
+ -
129
+ title: Miscellaneous
130
+ -
131
+ number: 0
132
+ title: First Window
133
+ -
134
+ number: 1
135
+ title: Processes
136
+ command: top
137
+ </pre></code>
138
+
139
+ This would result in 3 windows at launch. Window 0 would be named _First Window_ with a fresh command prompt, window 1 would be named _Processes_ and would be running the _top_ command. A third window, named _Miscellaneous_ would have a fresh command prompt, and be assigned to the first available number by Screen.
140
+
141
+ The *title*, *number*, and *command* definitions are all optional, though you must supply one. The value of the *command* is executed by Screen on launch, as-is. If you decide that _rm -FR_ is your command, it's not going to stop you.
142
+
143
+ h3. Nested Configurations
144
+
145
+ A nested configuration can be called by name from the ruby-screen command line utility. They can contain the same elements as a top-level configuration.
146
+
147
+ <pre><code>
148
+ startup_message: off
149
+ defscrollback: 5000
150
+
151
+ generic:
152
+ windows:
153
+ -
154
+ title: Miscellaneous
155
+ -
156
+ number: 1
157
+ title: Other Window
158
+
159
+ specific:
160
+ defscrollback: 1000
161
+ windows:
162
+ -
163
+ number: 1
164
+ title: Nested Window
165
+ </pre></code>
166
+
167
+ Nested configuration names are passed as the first argument to the *ruby-screen* command line utility. When this happens, the programs processes the configuration from the highest level down through the hierarchy to the configuration you specified, merging customizations and windows as it goes. Any customization keys or numbered windows that are duplicated deeper in the hierarchy will override those above them.
168
+
169
+ Calling the nested configuration named _specific_ above would use the Windows and Customizations specified in the top level and _generic_ configurations, but would override the number of lines of scroll buffer and the name of Window 1.
170
+
171
+ There is no limit on how far you can nest, apart from your own sanity.
172
+
173
+ h3. Paths
174
+
175
+ Use *working_directory* and *relative_directory* in instances where you will always want a certain configuration to launch with a specific working directory. This is the equivalent to manually traversing to the intended directory before launching the Screen command.
176
+
177
+ <pre><code>
178
+ startup_message: off
179
+
180
+ web_server_edit:
181
+ working_directory: /usr/local/my_web_server
182
+ windows:
183
+ -
184
+ name: Config
185
+ command: vim conf/my_web_server.conf
186
+ -
187
+ name: Log
188
+ command: tail -f server.log
189
+ </pre></code>
190
+
191
+ When running the *web_server_edit* configuration above, the commands will be executed in _/usr/local/my_web_server_. Any new windows you open within Screen will also default to that directory.
192
+
193
+ The working directory can also begin with a tilde character to indicate your home directory. _~/projects_ on a Linux system would translate to _/home/your_username/projects_. It is suggested that you use the tilde or a full path for your *working_directory* settings, so that RubyScreen can work as intended no matter where it is called from.
194
+
195
+ The *relative_directory* setting can be used in nested configurations and will be appended to the end of the current working directory.
196
+
197
+ h3. Misc
198
+
199
+ Before your configuration file is loaded by the YAML library it is processed by ERB, a Ruby templating system. Information on its syntax is available "here":http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/. Any Ruby can be executed inside of ERB, so review any configuration files before executing.
200
+
201
+ h2. Thanks
202
+
203
+ Thanks to the author of "this":http://mikeburnscoder.wordpress.com/2007/06/21/my-rails-development-environment-version-1-vim-and-screen/ blog posting, which got the ball rolling for me on launching Screen with predefined windows and commands.
204
+
205
+ h2. License
206
+
207
+ Copyright (c) 2008
208
+
209
+ Permission is hereby granted, free of charge, to any person obtaining
210
+ a copy of this software and associated documentation files (the
211
+ 'Software'), to deal in the Software without restriction, including
212
+ without limitation the rights to use, copy, modify, merge, publish,
213
+ distribute, sublicense, and/or sell copies of the Software, and to
214
+ permit persons to whom the Software is furnished to do so, subject to
215
+ the following conditions:
216
+
217
+ The above copyright notice and this permission notice shall be
218
+ included in all copies or substantial portions of the Software.
219
+
220
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
221
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
222
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
223
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
224
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
225
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
226
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ The documentation is in Readme.textile, but you're better off reading it here: http://github.com/dpetersen/ruby-screen/tree/master
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + '/../lib/ruby_screen'
2
+
3
+ RubyScreen.process ARGV
4
+
5
+ # vim: syntax=Ruby
@@ -0,0 +1,71 @@
1
+ require 'ruby_screen/version'
2
+
3
+ AUTHOR = 'Don Petersen' # can also be an array of Authors
4
+ EMAIL = "don@donpetersen.net"
5
+ DESCRIPTION = "Ruby command line utility to manage GNU Screen configurations, and launch Screen using those configuration."
6
+ GEM_NAME = 'ruby-screen' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'ruby-screen' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "dpetersen"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = RubyScreen::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'ruby_screen documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+
65
+ end
66
+
67
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ #hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
+ hoe.remote_rdoc_dir = '' # Release to root
71
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
+
17
+ require 'ruby_screen'
@@ -0,0 +1,14 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'ruby_screen/preferences_loader'
3
+ require 'ruby_screen/executer'
4
+ require 'ruby_screen/configuration/description'
5
+ require 'ruby_screen/configuration/parser'
6
+ require 'ruby_screen/configuration/generator'
7
+
8
+ module RubyScreen
9
+ def self.process(arguments)
10
+ preferences_hash = PreferencesLoader.load
11
+ description = Configuration::Parser.parse(arguments, preferences_hash)
12
+ Executer.new(description)
13
+ end
14
+ end
@@ -0,0 +1,60 @@
1
+ module RubyScreen::Configuration
2
+ class Description
3
+ attr_reader :customizations, :numbered_windows, :numberless_windows, :working_directory
4
+
5
+ def initialize
6
+ @customizations = {}
7
+ @numberless_windows = []
8
+ @numbered_windows = {}
9
+ end
10
+
11
+ def working_directory=(directory)
12
+ @working_directory ||= ""
13
+ process_directory(directory)
14
+ end
15
+
16
+ def append_directory(directory)
17
+ process_directory(directory, @working_directory)
18
+ end
19
+
20
+ def add_customization(key, value)
21
+ @customizations.store(key, value)
22
+ end
23
+
24
+ def add_window(options)
25
+ options.include?("number") ? add_numbered_window(options) : add_numberless_window(options)
26
+ end
27
+
28
+ def to_screen_configuration
29
+ Generator.new(self).to_screen_configuration
30
+ end
31
+
32
+ protected
33
+
34
+ def process_directory(directory, append = false)
35
+ @working_directory =
36
+ if directory[0].chr == "~"
37
+ File.expand_path(directory)
38
+ elsif append
39
+ @working_directory + "/" + strip_slashes(directory)
40
+ else
41
+ directory
42
+ end
43
+ end
44
+
45
+ def strip_slashes(s)
46
+ s.gsub!(/^\//, "")
47
+ s.gsub!(/\/$/, "")
48
+ s
49
+ end
50
+
51
+ def add_numberless_window(options)
52
+ @numberless_windows << options
53
+ end
54
+
55
+ def add_numbered_window(options)
56
+ number = options.delete("number")
57
+ @numbered_windows[number] = options
58
+ end
59
+ end
60
+ end