pry 0.10.3 → 0.14.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +439 -16
- data/LICENSE +1 -1
- data/README.md +362 -302
- data/bin/pry +4 -7
- data/lib/pry/basic_object.rb +10 -0
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +84 -97
- data/lib/pry/code/code_file.rb +37 -26
- data/lib/pry/code/code_range.rb +7 -5
- data/lib/pry/code/loc.rb +26 -13
- data/lib/pry/code.rb +42 -31
- data/lib/pry/code_object.rb +53 -28
- data/lib/pry/color_printer.rb +46 -35
- data/lib/pry/command.rb +197 -369
- data/lib/pry/command_set.rb +89 -114
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -82
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +85 -72
- data/lib/pry/commands/cat/file_formatter.rb +56 -46
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +62 -54
- data/lib/pry/commands/cd.rb +40 -35
- data/lib/pry/commands/change_inspector.rb +29 -22
- data/lib/pry/commands/change_prompt.rb +48 -23
- data/lib/pry/commands/clear_screen.rb +20 -0
- data/lib/pry/commands/code_collector.rb +148 -131
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +23 -34
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +34 -23
- data/lib/pry/commands/edit.rb +185 -157
- data/lib/pry/commands/exit.rb +40 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -16
- data/lib/pry/commands/find_method.rb +168 -162
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +151 -149
- data/lib/pry/commands/import_set.rb +20 -15
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +35 -28
- data/lib/pry/commands/ls/constants.rb +59 -31
- data/lib/pry/commands/ls/formatter.rb +42 -36
- data/lib/pry/commands/ls/globals.rb +38 -36
- data/lib/pry/commands/ls/grep.rb +17 -15
- data/lib/pry/commands/ls/instance_vars.rb +29 -28
- data/lib/pry/commands/ls/interrogatable.rb +18 -12
- data/lib/pry/commands/ls/jruby_hacks.rb +47 -41
- data/lib/pry/commands/ls/local_names.rb +26 -24
- data/lib/pry/commands/ls/local_vars.rb +38 -30
- data/lib/pry/commands/ls/ls_entity.rb +47 -52
- data/lib/pry/commands/ls/methods.rb +49 -51
- data/lib/pry/commands/ls/methods_helper.rb +46 -42
- data/lib/pry/commands/ls/self_methods.rb +23 -21
- data/lib/pry/commands/ls.rb +124 -103
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +92 -82
- data/lib/pry/commands/pry_backtrace.rb +22 -17
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +33 -27
- data/lib/pry/commands/reload_code.rb +60 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +57 -42
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +56 -29
- data/lib/pry/commands/shell_mode.rb +22 -18
- data/lib/pry/commands/show_doc.rb +80 -70
- data/lib/pry/commands/show_info.rb +194 -155
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +110 -42
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +20 -16
- data/lib/pry/commands/watch_expression/expression.rb +32 -27
- data/lib/pry/commands/watch_expression.rb +89 -84
- data/lib/pry/commands/whereami.rb +156 -141
- data/lib/pry/commands/wtf.rb +78 -40
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +310 -20
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +22 -9
- data/lib/pry/editor.rb +56 -34
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +13 -18
- data/lib/pry/forwardable.rb +27 -0
- data/lib/pry/helpers/base_helpers.rb +20 -62
- data/lib/pry/helpers/command_helpers.rb +52 -62
- data/lib/pry/helpers/documentation_helpers.rb +21 -12
- data/lib/pry/helpers/options_helpers.rb +15 -8
- data/lib/pry/helpers/platform.rb +55 -0
- data/lib/pry/helpers/table.rb +44 -32
- data/lib/pry/helpers/text.rb +96 -85
- data/lib/pry/helpers.rb +3 -0
- data/lib/pry/history.rb +81 -55
- data/lib/pry/hooks.rb +60 -110
- data/lib/pry/indent.rb +74 -68
- data/lib/pry/input_completer.rb +199 -158
- data/lib/pry/input_lock.rb +7 -10
- data/lib/pry/inspector.rb +36 -24
- data/lib/pry/last_exception.rb +45 -45
- data/lib/pry/method/disowned.rb +19 -5
- data/lib/pry/method/patcher.rb +14 -8
- data/lib/pry/method/weird_method_locator.rb +79 -45
- data/lib/pry/method.rb +178 -124
- data/lib/pry/object_path.rb +37 -28
- data/lib/pry/output.rb +102 -16
- data/lib/pry/pager.rb +187 -174
- data/lib/pry/prompt.rb +213 -25
- data/lib/pry/pry_class.rb +119 -98
- data/lib/pry/pry_instance.rb +261 -224
- data/lib/pry/repl.rb +83 -29
- data/lib/pry/repl_file_loader.rb +27 -22
- data/lib/pry/ring.rb +89 -0
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +190 -0
- data/lib/pry/slop/option.rb +210 -0
- data/lib/pry/slop.rb +672 -0
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +24 -0
- data/lib/pry/testable/mockable.rb +22 -0
- data/lib/pry/testable/pry_tester.rb +88 -0
- data/lib/pry/testable/utility.rb +34 -0
- data/lib/pry/testable/variables.rb +52 -0
- data/lib/pry/testable.rb +68 -0
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +20 -0
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +35 -32
- data/lib/pry/wrapped_module.rb +68 -63
- data/lib/pry.rb +133 -149
- metadata +58 -69
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -32
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gist.rb +0 -101
- data/lib/pry/commands/install_command.rb +0 -53
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/plugins.rb +0 -103
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/rubygem.rb +0 -82
- data/lib/pry/terminal.rb +0 -79
- data/lib/pry/test/helper.rb +0 -170
@@ -1,62 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
4
|
+
class Command
|
5
|
+
class ReloadCode < Pry::ClassCommand
|
6
|
+
match 'reload-code'
|
7
|
+
group 'Misc'
|
8
|
+
description 'Reload the source file that contains the specified code object.'
|
9
|
+
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Reload the source file that contains the specified code object.
|
12
|
+
|
13
|
+
e.g reload-code MyClass#my_method #=> reload a method
|
14
|
+
reload-code MyClass #=> reload a class
|
15
|
+
reload-code my-command #=> reload a pry command
|
16
|
+
reload-code self #=> reload the current object
|
17
|
+
reload-code #=> reload the current file or object
|
18
|
+
BANNER
|
19
|
+
|
20
|
+
def process
|
21
|
+
if !args.empty?
|
22
|
+
reload_object(args.join(" "))
|
23
|
+
elsif internal_binding?(target)
|
24
|
+
reload_object("self")
|
25
|
+
else
|
26
|
+
reload_current_file
|
27
|
+
end
|
24
28
|
end
|
25
|
-
end
|
26
29
|
|
27
|
-
|
30
|
+
private
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
def current_file
|
33
|
+
file =
|
34
|
+
if target.respond_to?(:source_location)
|
35
|
+
target.source_location.first
|
36
|
+
else
|
37
|
+
target.eval("__FILE__")
|
38
|
+
end
|
39
|
+
File.expand_path file
|
40
|
+
end
|
32
41
|
|
33
|
-
|
34
|
-
|
35
|
-
|
42
|
+
def reload_current_file
|
43
|
+
unless File.exist?(current_file)
|
44
|
+
raise CommandError, "Current file: #{current_file} cannot be found on disk!"
|
45
|
+
end
|
46
|
+
|
47
|
+
load current_file
|
48
|
+
output.puts "The current file: #{current_file} was reloaded!"
|
36
49
|
end
|
37
50
|
|
38
|
-
|
39
|
-
|
40
|
-
|
51
|
+
def reload_object(identifier)
|
52
|
+
code_object = Pry::CodeObject.lookup(identifier, pry_instance)
|
53
|
+
check_for_reloadability(code_object, identifier)
|
54
|
+
load code_object.source_file
|
55
|
+
output.puts "#{identifier} was reloaded!"
|
56
|
+
end
|
41
57
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
58
|
+
def check_for_reloadability(code_object, identifier)
|
59
|
+
if !code_object || !code_object.source_file
|
60
|
+
raise CommandError, "Cannot locate #{identifier}!"
|
61
|
+
end
|
62
|
+
|
63
|
+
return if File.exist?(code_object.source_file)
|
48
64
|
|
49
|
-
def check_for_reloadability(code_object, identifier)
|
50
|
-
if !code_object || !code_object.source_file
|
51
|
-
raise CommandError, "Cannot locate #{identifier}!"
|
52
|
-
elsif !File.exists?(code_object.source_file)
|
53
65
|
raise CommandError,
|
54
|
-
|
55
|
-
|
66
|
+
"Cannot reload #{identifier} as it has no associated file on disk. " \
|
67
|
+
"File found was: #{code_object.source_file}"
|
56
68
|
end
|
57
69
|
end
|
58
|
-
end
|
59
70
|
|
60
|
-
|
61
|
-
|
71
|
+
Pry::Commands.add_command(Pry::Command::ReloadCode)
|
72
|
+
Pry::Commands.alias_command 'reload-method', 'reload-code'
|
73
|
+
end
|
62
74
|
end
|
data/lib/pry/commands/reset.rb
CHANGED
@@ -1,18 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class Reset < Pry::ClassCommand
|
6
|
+
match 'reset'
|
7
|
+
group 'Context'
|
8
|
+
description 'Reset the REPL to a clean state.'
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Reset the REPL to a clean state.
|
12
|
+
BANNER
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
def process
|
15
|
+
output.puts 'Pry reset.'
|
16
|
+
exec 'pry'
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
20
|
+
Pry::Commands.add_command(Pry::Command::Reset)
|
21
|
+
end
|
18
22
|
end
|
data/lib/pry/commands/ri.rb
CHANGED
@@ -1,60 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
1
5
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
+
class Command
|
7
|
+
class Ri < Pry::ClassCommand
|
8
|
+
match 'ri'
|
9
|
+
group 'Introspection'
|
10
|
+
description 'View ri documentation.'
|
6
11
|
|
7
|
-
|
8
|
-
|
12
|
+
banner <<-'BANNER'
|
13
|
+
Usage: ri [spec]
|
9
14
|
|
10
|
-
|
11
|
-
|
15
|
+
View ri documentation. Relies on the "rdoc" gem being installed.
|
16
|
+
See also "show-doc" command.
|
12
17
|
|
13
|
-
|
14
|
-
|
18
|
+
ri Array#each
|
19
|
+
BANNER
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
def process(spec)
|
22
|
+
unless spec
|
23
|
+
return output.puts(
|
24
|
+
"Please provide a class, module, or method name (e.g: ri Array#push)"
|
25
|
+
)
|
26
|
+
end
|
19
27
|
|
20
|
-
|
28
|
+
# Lazily load RI
|
29
|
+
require 'rdoc/ri/driver'
|
21
30
|
|
22
|
-
|
23
|
-
subclass = Class.new(RDoc::RI::Driver) # the hard way.
|
31
|
+
unless defined? RDoc::RI::PryDriver
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@pager.page(paging_text.string)
|
34
|
-
end
|
33
|
+
# Subclass RI so that it formats its output nicely, and uses `lesspipe`.
|
34
|
+
subclass = Class.new(RDoc::RI::Driver) # the hard way.
|
35
|
+
|
36
|
+
subclass.class_eval do
|
37
|
+
def initialize(pager, opts)
|
38
|
+
@pager = pager
|
39
|
+
super opts
|
40
|
+
end
|
35
41
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
def page
|
43
|
+
paging_text = StringIO.new
|
44
|
+
yield paging_text
|
45
|
+
@pager.page(paging_text.string)
|
46
|
+
end
|
47
|
+
|
48
|
+
def formatter(_io)
|
49
|
+
if @formatter_klass
|
50
|
+
@formatter_klass.new
|
51
|
+
else
|
52
|
+
RDoc::Markup::ToAnsi.new
|
53
|
+
end
|
41
54
|
end
|
42
55
|
end
|
43
|
-
end
|
44
56
|
|
45
|
-
|
46
|
-
|
57
|
+
RDoc::RI.const_set :PryDriver, subclass # hook it up!
|
58
|
+
end
|
47
59
|
|
48
|
-
|
49
|
-
|
60
|
+
# Spin-up an RI insance.
|
61
|
+
ri = RDoc::RI::PryDriver.new(
|
62
|
+
pry_instance.pager, use_stdout: true, interactive: false
|
63
|
+
)
|
50
64
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
65
|
+
begin
|
66
|
+
ri.display_names [spec] # Get the documentation (finally!)
|
67
|
+
rescue RDoc::RI::Driver::NotFoundError => e
|
68
|
+
output.puts "error: '#{e.name}' not found"
|
69
|
+
end
|
55
70
|
end
|
56
71
|
end
|
57
|
-
end
|
58
72
|
|
59
|
-
|
73
|
+
Pry::Commands.add_command(Pry::Command::Ri)
|
74
|
+
end
|
60
75
|
end
|
@@ -1,61 +1,63 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Pry
|
4
|
-
class Command
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class Command
|
5
|
+
class SaveFile < Pry::ClassCommand
|
6
|
+
match 'save-file'
|
7
|
+
group 'Input and Output'
|
8
|
+
description 'Export to a file using content from the REPL.'
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: save-file [OPTIONS] --to [FILE]
|
11
12
|
|
12
|
-
|
13
|
+
Export to a file using content from the REPL.
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
save-file my_method --to hello.rb
|
16
|
+
save-file -i 1..10 --to hello.rb --append
|
17
|
+
save-file show-method --to my_command.rb
|
18
|
+
save-file sample_file.rb --lines 2..10 --to output_file.rb
|
19
|
+
BANNER
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def options(opt)
|
22
|
+
CodeCollector.inject_options(opt)
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
opt.on :to=, "Specify the output file path"
|
25
|
+
opt.on :a, :append, "Append output to file"
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def process
|
29
|
+
@cc = CodeCollector.new(args, opts, pry_instance)
|
30
|
+
raise CommandError, "Found no code to save." if @cc.content.empty?
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if !file_name
|
33
|
+
display_content
|
34
|
+
else
|
35
|
+
save_file
|
36
|
+
end
|
35
37
|
end
|
36
|
-
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def file_name
|
40
|
+
opts[:to] || nil
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def save_file
|
44
|
+
File.open(file_name, mode) do |f|
|
45
|
+
f.puts @cc.content
|
46
|
+
end
|
47
|
+
output.puts "#{file_name} successfully saved"
|
45
48
|
end
|
46
|
-
output.puts "#{file_name} successfully saved"
|
47
|
-
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def display_content
|
51
|
+
output.puts @cc.content
|
52
|
+
output.puts "\n\n--\nPlease use `--to FILE` to export to a file."
|
53
|
+
output.puts "No file saved!\n--"
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
def mode
|
57
|
+
opts.present?(:append) ? "a" : "w"
|
58
|
+
end
|
57
59
|
end
|
58
|
-
end
|
59
60
|
|
60
|
-
|
61
|
+
Pry::Commands.add_command(Pry::Command::SaveFile)
|
62
|
+
end
|
61
63
|
end
|
@@ -1,48 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
pass_block(cmd)
|
23
|
-
if command_block
|
24
|
-
command_block.call `#{cmd}`
|
4
|
+
class Command
|
5
|
+
class ShellCommand < Pry::ClassCommand
|
6
|
+
match(/\.(.*)/)
|
7
|
+
group 'Input and Output'
|
8
|
+
description "All text following a '.' is forwarded to the shell."
|
9
|
+
command_options listing: '.<shell command>', use_prefix: false,
|
10
|
+
takes_block: true
|
11
|
+
|
12
|
+
banner <<-'BANNER'
|
13
|
+
Usage: .COMMAND_NAME
|
14
|
+
|
15
|
+
All text following a "." is forwarded to the shell.
|
16
|
+
|
17
|
+
.ls -aF
|
18
|
+
.uname
|
19
|
+
BANNER
|
20
|
+
|
21
|
+
def process(cmd)
|
22
|
+
if cmd =~ /^cd\s*(.*)/i
|
23
|
+
process_cd parse_destination(Regexp.last_match(1))
|
25
24
|
else
|
26
|
-
|
25
|
+
pass_block(cmd)
|
26
|
+
if command_block
|
27
|
+
command_block.call `#{cmd}`
|
28
|
+
else
|
29
|
+
pry_instance.config.system.call(output, cmd, pry_instance)
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
29
|
-
end
|
30
33
|
|
31
|
-
|
34
|
+
private
|
32
35
|
|
33
36
|
def parse_destination(dest)
|
34
37
|
return "~" if dest.empty?
|
35
38
|
return dest unless dest == "-"
|
39
|
+
|
36
40
|
state.old_pwd || raise(CommandError, "No prior directory available")
|
37
41
|
end
|
38
42
|
|
39
43
|
def process_cd(dest)
|
40
44
|
state.old_pwd = Dir.pwd
|
41
|
-
Dir.chdir
|
45
|
+
Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest))
|
42
46
|
rescue Errno::ENOENT
|
43
47
|
raise CommandError, "No such directory: #{dest}"
|
44
48
|
end
|
45
|
-
end
|
46
49
|
|
47
|
-
|
50
|
+
def cd_path_env
|
51
|
+
Pry::Env['CDPATH']
|
52
|
+
end
|
53
|
+
|
54
|
+
def cd_path_exists?
|
55
|
+
cd_path_env && cd_path_env.length.nonzero?
|
56
|
+
end
|
57
|
+
|
58
|
+
def path_from_cd_path(dest)
|
59
|
+
return if !(dest && cd_path_exists?) || special_case_path?(dest)
|
60
|
+
|
61
|
+
cd_path_env.split(File::PATH_SEPARATOR).each do |path|
|
62
|
+
return path if File.directory?(path) && path.split(File::SEPARATOR).last == dest
|
63
|
+
end
|
64
|
+
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def special_case_path?(dest)
|
69
|
+
['.', '..', '-'].include?(dest) || dest =~ /\A[#{File::PATH_SEPARATOR}~]/
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
Pry::Commands.add_command(Pry::Command::ShellCommand)
|
74
|
+
end
|
48
75
|
end
|
@@ -1,25 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Pry
|
2
|
-
class Command
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
class Command
|
5
|
+
class ShellMode < Pry::ClassCommand
|
6
|
+
match 'shell-mode'
|
7
|
+
group 'Input and Output'
|
8
|
+
description 'Toggle shell mode. Bring in pwd prompt and file completion.'
|
9
|
+
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Toggle shell mode. Bring in pwd prompt and file completion.
|
12
|
+
BANNER
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
BANNER
|
14
|
+
def process
|
15
|
+
state.disabled ^= true
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
_pry_.push_prompt Pry::SHELL_PROMPT
|
18
|
-
_pry_.custom_completions = _pry_.config.command_completions
|
17
|
+
if state.disabled
|
18
|
+
state.prev_prompt = pry_instance.prompt
|
19
|
+
pry_instance.prompt = Pry::Prompt[:shell]
|
20
|
+
else
|
21
|
+
pry_instance.prompt = state.prev_prompt
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
|
-
end
|
22
25
|
|
23
|
-
|
24
|
-
|
26
|
+
Pry::Commands.add_command(Pry::Command::ShellMode)
|
27
|
+
Pry::Commands.alias_command 'file-mode', 'shell-mode'
|
28
|
+
end
|
25
29
|
end
|