shell_shock 0.0.1

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.
Files changed (4) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +23 -0
  3. data/lib/shell_shock/context.rb +52 -0
  4. metadata +81 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mark Ryall
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
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = Shell Shock
2
+
3
+ A library for creating command line shell application.
4
+
5
+ == Rationale
6
+
7
+ * command line tools are faster and cooler than any gui or web interface
8
+ * tab completion is awesome
9
+ * cutting and pasting code is bad
10
+
11
+ == Installation
12
+
13
+ gem install shell_shock
14
+
15
+ == Usage
16
+
17
+ Here's a sample shell application using shell shock:
18
+
19
+ require '
20
+
21
+ class RootContext
22
+
23
+ end
@@ -0,0 +1,52 @@
1
+ require 'readline'
2
+ require 'rubygems'
3
+ require 'active_support/inflector'
4
+
5
+ module ShellShock
6
+ module Context
7
+ def refresh
8
+ commands = respond_to?(:refresh_commands) ? refresh_commands : []
9
+ Readline.completion_proc = lambda do |text|
10
+ (commands + @commands.keys + ['quit', 'exit']).grep( /^#{Regexp.escape(text)}/ ).sort
11
+ end
12
+ Readline.completer_word_break_characters = ''
13
+ end
14
+
15
+ def push
16
+ refresh
17
+ begin
18
+ while line = Readline.readline(@prompt_text, true)
19
+ line.strip!
20
+ case line
21
+ when 'quit','exit'
22
+ return
23
+ when /(\w+) (.*)/
24
+ process_command $1, $2
25
+ when /(\w+)/
26
+ process_command $1
27
+ else
28
+ puts 'unknown command'
29
+ end
30
+ puts
31
+ refresh
32
+ end
33
+ rescue Interrupt => e
34
+ return
35
+ end
36
+ puts
37
+ end
38
+
39
+ def process_command name, parameter=nil
40
+ m = "#{name}_command".to_sym
41
+ if respond_to?(m)
42
+ send(m, parameter)
43
+ return
44
+ end
45
+ if @commands[name]
46
+ @commands[name].execute parameter
47
+ else
48
+ @io.say 'unknown command'
49
+ end
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shell_shock
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Mark Ryall
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-11 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 5
31
+ version: 2.3.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: |
35
+ This is just some code extracted from a few command line gems i've created (shh and cardigan).
36
+
37
+ I wanted to move the shared functionality (related to creating a shell with readline) to a seperate gem.'
38
+
39
+ email: mark@ryall.name
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - lib/shell_shock/context.rb
48
+ - README.rdoc
49
+ - MIT-LICENSE
50
+ has_rdoc: true
51
+ homepage: http://github.com/markryall/shell_shock
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: library for creating simple shell applications using readline
80
+ test_files: []
81
+