ripl-commands 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec CHANGED
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.description = "This ripl plugin provides a core group of commands for any ripl shell. It aims to match and surpass functionality in irb's commands."
13
13
  s.required_rubygems_version = ">= 1.3.6"
14
14
  s.rubyforge_project = 'tagaholic'
15
+ s.add_dependency 'ripl', '>= 0.2.7'
15
16
  s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
16
17
  s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
17
18
  s.license = 'MIT'
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.2.0
2
+ * Add history and editor commands
3
+
1
4
  == 0.1.1
2
5
  * Fix 1.9 bug thanks to @janlelis
3
6
 
data/README.rdoc CHANGED
@@ -44,7 +44,31 @@ Try it out:
44
44
 
45
45
  # To list what commands ripl has
46
46
  >> list
47
- => ["list", "config", "jumps", "jump"]
47
+ => ["list", "config", "history", "editor", "jumps", "jump"]
48
+
49
+ This plugin also comes with commands to see history and prototype code easily in an editor:
50
+
51
+ # Display last 10 inputs
52
+ >> history 10
53
+ 10 : class Porque; def no; 'porque'; end; end
54
+ 9 : Porque.no
55
+ 8 : Porque.no
56
+ 7: %w{can you -dig -this sir?}.inject([]) do |arr, e|
57
+ 6: if e[/^-/] .. e[/^[^-]/]
58
+ 5: break(arr) if e[/^[^-]/]
59
+ 4: arr << e
60
+ 3: end
61
+ 2: arr
62
+ 1: end
63
+ => ...
64
+
65
+ # Edit last 7 inputs in an editor (specified by ENV['EDITOR']) and eval the edited text
66
+ >> editor 7
67
+ ....
68
+ => ['dig', '-this']
69
+
70
+ # If a previous edit exists, opens it in an editor, otherwise opens a new file
71
+ >> editor
48
72
 
49
73
  == Extending Commands
50
74
 
data/deps.rip ADDED
@@ -0,0 +1 @@
1
+ ripl >=0.2.7
@@ -0,0 +1,44 @@
1
+ require 'tempfile'
2
+
3
+ module Ripl::Commands::History
4
+ def history(*args)
5
+ Ripl::Commands::History.history(*args)
6
+ end
7
+
8
+ def editor(*args)
9
+ Ripl::Commands::History.edit(*args)
10
+ end
11
+
12
+ class << self
13
+ def history(last=10)
14
+ slice_history(last).each_with_index do |e,i|
15
+ puts "#{last - i}: #{e}"
16
+ end
17
+ end
18
+
19
+ def edit(last=nil)
20
+ body = if last.nil? && @last_edit
21
+ @last_edit
22
+ elsif last.is_a?(Fixnum)
23
+ start = Array(Ripl.shell.history)[-2][/^history/] ? 2 : 1
24
+ slice_history(last, start).join("\n")
25
+ else
26
+ ''
27
+ end
28
+ file = Tempfile.new('edit_string').path
29
+ File.open(file, 'w') {|f| f.puts(body) }
30
+ system(editor, file)
31
+ Ripl.shell.loop_eval(@last_edit = File.read(file))
32
+ end
33
+
34
+ def editor
35
+ ENV['EDITOR'] ? ENV['EDITOR'][/\w+/] : 'vim'
36
+ end
37
+
38
+ def slice_history(last, start=1)
39
+ Array(Ripl.shell.history).reverse.slice(start, last).reverse
40
+ end
41
+ end
42
+ end
43
+
44
+ Ripl::Commands.send :include, Ripl::Commands::History
data/lib/ripl/commands.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'ripl'
2
+ require 'ripl/commands/history'
2
3
 
3
4
  module Ripl
4
5
  module Commands
5
- VERSION = '0.1.1'
6
+ VERSION = '0.2.0'
6
7
 
7
8
  module Core
8
9
  def self.jumps
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripl-commands
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabriel Horner
@@ -15,10 +15,25 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-19 00:00:00 -05:00
18
+ date: 2010-12-05 00:00:00 -05:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: ripl
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 7
34
+ version: 0.2.7
35
+ type: :runtime
36
+ version_requirements: *id001
22
37
  description: This ripl plugin provides a core group of commands for any ripl shell. It aims to match and surpass functionality in irb's commands.
23
38
  email: gabriel.horner@gmail.com
24
39
  executables: []
@@ -29,10 +44,12 @@ extra_rdoc_files:
29
44
  - README.rdoc
30
45
  - LICENSE.txt
31
46
  files:
47
+ - lib/ripl/commands/history.rb
32
48
  - lib/ripl/commands.rb
33
49
  - LICENSE.txt
34
50
  - CHANGELOG.rdoc
35
51
  - README.rdoc
52
+ - deps.rip
36
53
  - Rakefile
37
54
  - .gemspec
38
55
  has_rdoc: true