pry-de 0.0.0 → 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/VERSION +1 -1
  2. data/lib/pry-de.rb +53 -21
  3. data/pry-de.gemspec +2 -2
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/lib/pry-de.rb CHANGED
@@ -3,72 +3,104 @@ require 'pry'
3
3
  module PryDe
4
4
 
5
5
  Commands = Pry::CommandSet.new do
6
+ def psuedo_alias dest, src
7
+ command dest, "Alias for `#{src}`" do
8
+ run src
9
+ end
10
+ end
6
11
  # pry-debugger shortcuts:
7
- Pry.commands.alias_command ',b', 'break'
8
- Pry.commands.alias_command ',s', 'step'
9
- Pry.commands.alias_command ',n', 'next'
10
- Pry.commands.alias_command ',c', 'continue'
11
- Pry.commands.alias_command ',f', 'finish'
12
+ psuedo_alias ',b', 'break'
13
+ psuedo_alias ',s', 'step'
14
+ psuedo_alias ',n', 'next'
15
+ psuedo_alias ',c', 'continue'
16
+ psuedo_alias ',f', 'finish'
12
17
 
13
- Pry.commands.command ',-',
18
+ command ',loc', 'Show hash of local vars' do |*args|
19
+ pry_vars = [
20
+ :____, :___, :__, :_, :_dir_, :_file_, :_ex_, :_pry_, :_out_, :_in_ ]
21
+ loc_names = target.eval('local_variables').reject do |e|
22
+ pry_vars.include? e
23
+ end
24
+ name_value_pairs = loc_names.map do |name|
25
+ [name, (target.eval name.to_s)]
26
+ end
27
+ name_value_pairs.sort! do |(a,av), (b,bv)|
28
+ bv.to_s.size <=> av.to_s.size
29
+ end
30
+ Pry.print.call _pry_.output, Hash[name_value_pairs]
31
+ end
32
+
33
+ command ',-',
14
34
  'Remove last item from history, in preparation for a `play` command' do
15
35
  fail 'Newer (possibly Github) pry needed' unless
16
36
  _pry_.input_array.respond_to? :pop!
17
37
  _pry_.input_array.pop!
18
38
  end
19
39
 
20
- Pry.commands.command ',m', 'play method body only' do
40
+ command ',m', 'play method body only' do
21
41
  run_command 'play --lines 2..-2 -m'
22
42
  end
23
43
 
24
- # Hackish, but comes in handy, e.g. due to vim's dir browsing (:Ex)
25
- Pry.commands.command ',l', 'edit lib/' do
44
+ # Hopefully this will be of diminished employment, as more direct routes
45
+ # to the desired file:line grow, but for now it's a good all-purpose "edit"
46
+ command ',lib', 'edit lib/' do
26
47
  run 'edit lib/'
27
48
  IO.popen('git status --porcelain -- lib').readlines.each do |dirty|
28
49
  load dirty.split(' ').last
29
50
  end
30
51
  end
31
52
 
32
- Pry.commands.command ',r', 'Rerun previous command, like "r" in zsh' do
53
+ command ',r', 'Rerun previous command, like "r" in zsh' do
33
54
  run 'history --replay -1'
34
55
  end
35
56
 
36
- Pry.commands.command '?$', 'show-doc + show-source' do
37
- run '? ' + arg_string
57
+ command '?$', 'show-doc + show-source' do
58
+ begin
59
+ run '? ' + arg_string
60
+ rescue Pry::CommandError => e
61
+ output.puts text.bold('Behold: ') + e.message
62
+ end
38
63
  run '$ ' + arg_string
39
64
  end
40
65
 
41
66
  # TODO: ,clip ⇒ cat -i; clipit -i $stdin.readline.chomp
42
67
 
68
+ command /(.+,;.+)/ do |line|
69
+ cmds = line.split /\s*,;\s*/
70
+ cmds.each do |cmd|
71
+ run cmd
72
+ end
73
+ end
74
+
43
75
  # ,, aliases all the ",cmd"s to "cmd". Undo with a second ",,"
44
76
  # I'll promise not to use x and y, so they can always be metasyntactic.
45
77
  # …but the rest are fair game.
46
- Pry.commands.command ',,',
78
+ command ',,',
47
79
  'toggle ,-prefixes off/on commands, for terse input' do
48
80
  abbreviations = []
49
- Pry.commands.commands.keys.reject do |cmd|
81
+ commands.keys.reject do |cmd|
50
82
  cmd.class != String or cmd[0] != ',' or cmd == ',,'
51
83
  end.each do |e|
52
84
  terse = e[1..-1]
53
85
  # TODO: check to see if you're stomping on something, first.
54
- Pry.commands.alias_command terse, e
86
+ alias_command terse, e
55
87
  abbreviations << terse
56
88
  end
57
- Pry.commands.command ',,', 'unsplat all ,-commands' do
89
+ command ',,', 'unsplat all ,-commands' do
58
90
  abbreviations.each do |too_terse|
59
- Pry.commands.delete too_terse
91
+ delete too_terse
60
92
  end
61
93
  end
62
94
  Pry.output.puts "Added commands: #{abbreviations.join ' '}"
63
95
  end
64
96
 
65
- Pry.commands.block_command /[$?]?\s*(.*?)\s*,,e\s*(.*)/,
97
+ block_command /[$?]?\s*(.*?)\s*,,e\s*(.*)/,
66
98
  'edit from anywhere on the line' do |a,b|
67
99
  run "edit #{a} #{b}"
68
100
  end
69
101
 
70
102
  # I want this upstreamed as cat --EX
71
- Pry.commands.command 'cat--EX', 'show whole backtrace' do
103
+ command 'cat--EX', 'show whole backtrace' do
72
104
  ex = _pry_.last_exception
73
105
  count = ex.backtrace.count
74
106
  (0...count).each do |v|
@@ -81,7 +113,7 @@ module PryDe
81
113
  # Follow pry-doc further, e.g.:
82
114
  # $ [].push
83
115
  # C$ rb_ary_modify
84
- Pry.commands.command 'C$', 'Hop to tag in the Ruby C source' do
116
+ command 'C$', 'Hop to tag in the Ruby C source' do
85
117
  # TODO: Also check the dirs where rvm and ruby-build place trees.
86
118
  src_dir = ENV['RUBY_SRC_DIR'] || ENV['HOME']+'/pkg'
87
119
  unless Dir.exist? src_dir
@@ -109,4 +141,4 @@ module PryDe
109
141
  end
110
142
  end
111
143
 
112
- Pry.commands.import PryDe::Commands
144
+ Pry.config.commands.import PryDe::Commands
data/pry-de.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "pry-de"
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["\u{2608}king", "Banisterfiend"]
12
- s.date = "2012-09-20"
12
+ s.date = "2012-09-25"
13
13
  s.description = "For the concept, see: https://github.com/pry/pry/wiki/pry-de"
14
14
  s.email = "pry-de@sharpsaw.org"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-de
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-20 00:00:00.000000000 Z
13
+ date: 2012-09-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pry
@@ -176,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  segments:
178
178
  - 0
179
- hash: 3429421329060892323
179
+ hash: 4324804412131049766
180
180
  required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  none: false
182
182
  requirements: