pry 0.10.pre.1-i386-mingw32 → 0.10.0.pre3-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +122 -183
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +23 -0
- data/lib/pry/commands/find_method.rb +193 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +32 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +24 -0
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/completion.rb +0 -221
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -0,0 +1,29 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::GemOpen < Pry::ClassCommand
|
3
|
+
match 'gem-open'
|
4
|
+
group 'Gems'
|
5
|
+
description 'Opens the working directory of the gem in your editor.'
|
6
|
+
command_options :argument_required => true
|
7
|
+
|
8
|
+
banner <<-'BANNER'
|
9
|
+
Usage: gem-open GEM_NAME
|
10
|
+
|
11
|
+
Change the current working directory to that in which the given gem is
|
12
|
+
installed, and then opens your text editor.
|
13
|
+
|
14
|
+
gem-open pry-exception_explorer
|
15
|
+
BANNER
|
16
|
+
|
17
|
+
def process(gem)
|
18
|
+
Dir.chdir(Rubygem.spec(gem).full_gem_path) do
|
19
|
+
Pry::Editor.invoke_editor(".", 0, false)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def complete(str)
|
24
|
+
Rubygem.complete(str)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Pry::Commands.add_command(Pry::Command::GemOpen)
|
29
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Gist < Pry::ClassCommand
|
3
|
+
match 'gist'
|
4
|
+
group 'Misc'
|
5
|
+
description 'Upload code, docs, history to https://gist.github.com/.'
|
6
|
+
command_options :requires_gem => "gist"
|
7
|
+
|
8
|
+
banner <<-'BANNER'
|
9
|
+
Usage: gist [OPTIONS] [--help]
|
10
|
+
|
11
|
+
The gist command enables you to gist code from files and methods to github.
|
12
|
+
|
13
|
+
gist -i 20 --lines 1..3
|
14
|
+
gist Pry#repl --lines 1..-1
|
15
|
+
gist Rakefile --lines 5
|
16
|
+
BANNER
|
17
|
+
|
18
|
+
def setup
|
19
|
+
require 'gist'
|
20
|
+
end
|
21
|
+
|
22
|
+
def options(opt)
|
23
|
+
CodeCollector.inject_options(opt)
|
24
|
+
opt.on :login, "Authenticate the gist gem with GitHub"
|
25
|
+
opt.on :p, :public, "Create a public gist (default: false)", :default => false
|
26
|
+
opt.on :clip, "Copy the selected content to clipboard instead, do NOT gist it", :default => false
|
27
|
+
end
|
28
|
+
|
29
|
+
def process
|
30
|
+
return ::Gist.login! if opts.present?(:login)
|
31
|
+
cc = CodeCollector.new(args, opts, _pry_)
|
32
|
+
|
33
|
+
if cc.content =~ /\A\s*\z/
|
34
|
+
raise CommandError, "Found no code to gist."
|
35
|
+
end
|
36
|
+
|
37
|
+
if opts.present?(:clip)
|
38
|
+
clipboard_content(cc.content)
|
39
|
+
else
|
40
|
+
# we're overriding the default behavior of the 'in' option (as
|
41
|
+
# defined on CodeCollector) with our local behaviour.
|
42
|
+
content = opts.present?(:in) ? input_content : cc.content
|
43
|
+
gist_content content, cc.file
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def clipboard_content(content)
|
48
|
+
::Gist.copy(content)
|
49
|
+
output.puts "Copied content to clipboard!"
|
50
|
+
end
|
51
|
+
|
52
|
+
def input_content
|
53
|
+
content = ""
|
54
|
+
CodeCollector.input_expression_ranges.each do |range|
|
55
|
+
input_expressions = _pry_.input_array[range] || []
|
56
|
+
Array(input_expressions).each_with_index do |code, index|
|
57
|
+
corrected_index = index + range.first
|
58
|
+
if code && code != ""
|
59
|
+
content << code
|
60
|
+
if code !~ /;\Z/
|
61
|
+
content << "#{comment_expression_result_for_gist(_pry_.config.gist.inspecter.call(_pry_.output_array[corrected_index]))}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
content
|
68
|
+
end
|
69
|
+
|
70
|
+
def comment_expression_result_for_gist(result)
|
71
|
+
content = ""
|
72
|
+
result.lines.each_with_index do |line, index|
|
73
|
+
if index == 0
|
74
|
+
content << "# => #{line}"
|
75
|
+
else
|
76
|
+
content << "# #{line}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
content
|
81
|
+
end
|
82
|
+
|
83
|
+
def gist_content(content, filename)
|
84
|
+
response = ::Gist.gist(content, :filename => filename || "pry_gist.rb", :public => !!opts[:p])
|
85
|
+
if response
|
86
|
+
url = response['html_url']
|
87
|
+
message = "Gist created at URL #{url}"
|
88
|
+
begin
|
89
|
+
::Gist.copy(url)
|
90
|
+
message << ", which is now in the clipboard."
|
91
|
+
rescue ::Gist::ClipboardError
|
92
|
+
end
|
93
|
+
|
94
|
+
output.puts message
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Pry::Commands.add_command(Pry::Command::Gist)
|
100
|
+
Pry::Commands.alias_command 'clipit', 'gist --clip'
|
101
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Help < Pry::ClassCommand
|
3
|
+
match 'help'
|
4
|
+
group 'Help'
|
5
|
+
description 'Show a list of commands or information about a specific command.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: help [COMMAND]
|
9
|
+
|
10
|
+
With no arguments, help lists all the available commands along with their
|
11
|
+
descriptions. When given a command name as an argument, shows the help
|
12
|
+
for that command.
|
13
|
+
BANNER
|
14
|
+
|
15
|
+
# We only want to show commands that have descriptions, so that the
|
16
|
+
# easter eggs don't show up.
|
17
|
+
def visible_commands
|
18
|
+
visible = {}
|
19
|
+
commands.each do |key, command|
|
20
|
+
visible[key] = command if command.description && !command.description.empty?
|
21
|
+
end
|
22
|
+
visible
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get a hash of available commands grouped by the "group" name.
|
26
|
+
def command_groups
|
27
|
+
visible_commands.values.group_by(&:group)
|
28
|
+
end
|
29
|
+
|
30
|
+
def process
|
31
|
+
if args.empty?
|
32
|
+
display_index(command_groups)
|
33
|
+
else
|
34
|
+
display_search(args.first)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Display the index view, with headings and short descriptions per command.
|
39
|
+
#
|
40
|
+
# @param [Hash<String, Array<Commands>>] groups
|
41
|
+
def display_index(groups)
|
42
|
+
help_text = []
|
43
|
+
|
44
|
+
sorted_group_names(groups).each do |group_name|
|
45
|
+
commands = sorted_commands(groups[group_name])
|
46
|
+
|
47
|
+
if commands.any?
|
48
|
+
help_text << help_text_for_commands(group_name, commands)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
_pry_.pager.page help_text.join("\n\n")
|
53
|
+
end
|
54
|
+
|
55
|
+
# Given a group name and an array of commands,
|
56
|
+
# return the help string for those commands.
|
57
|
+
#
|
58
|
+
# @param [String] name The group name.
|
59
|
+
# @param [Array<Pry::Command>] commands
|
60
|
+
# @return [String] The generated help string.
|
61
|
+
def help_text_for_commands(name, commands)
|
62
|
+
"#{text.bold(name.capitalize)}\n" << commands.map do |command|
|
63
|
+
" #{command.options[:listing].to_s.ljust(18)} #{command.description.capitalize}"
|
64
|
+
end.join("\n")
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param [Hash] groups
|
68
|
+
# @return [Array<String>] An array of sorted group names.
|
69
|
+
def sorted_group_names(groups)
|
70
|
+
groups.keys.sort_by(&method(:group_sort_key))
|
71
|
+
end
|
72
|
+
|
73
|
+
# Sort an array of commands by their `listing` name.
|
74
|
+
#
|
75
|
+
# @param [Array<Pry::Command>] commands The commands to sort
|
76
|
+
# @return [Array<Pry::Command>] commands sorted by listing name.
|
77
|
+
def sorted_commands(commands)
|
78
|
+
commands.sort_by{ |command| command.options[:listing].to_s }
|
79
|
+
end
|
80
|
+
|
81
|
+
# Display help for an individual command or group.
|
82
|
+
#
|
83
|
+
# @param [String] search The string to search for.
|
84
|
+
def display_search(search)
|
85
|
+
if command = command_set.find_command_for_help(search)
|
86
|
+
display_command(command)
|
87
|
+
else
|
88
|
+
display_filtered_search_results(search)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Display help for a searched item, filtered first by group
|
93
|
+
# and if that fails, filtered by command name.
|
94
|
+
#
|
95
|
+
# @param [String] search The string to search for.
|
96
|
+
def display_filtered_search_results(search)
|
97
|
+
groups = search_hash(search, command_groups)
|
98
|
+
|
99
|
+
if groups.size > 0
|
100
|
+
display_index(groups)
|
101
|
+
else
|
102
|
+
display_filtered_commands(search)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Display help for a searched item, filtered by group
|
107
|
+
#
|
108
|
+
# @param [String] search The string to search for.
|
109
|
+
def display_filtered_commands(search)
|
110
|
+
filtered = search_hash(search, visible_commands)
|
111
|
+
raise CommandError, "No help found for '#{args.first}'" if filtered.empty?
|
112
|
+
|
113
|
+
if filtered.size == 1
|
114
|
+
display_command(filtered.values.first)
|
115
|
+
else
|
116
|
+
display_index({"'#{search}' commands" => filtered.values})
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Display help for an individual command.
|
121
|
+
#
|
122
|
+
# @param [Pry::Command] command
|
123
|
+
def display_command(command)
|
124
|
+
_pry_.pager.page command.new.help
|
125
|
+
end
|
126
|
+
|
127
|
+
# Find a subset of a hash that matches the user's search term.
|
128
|
+
#
|
129
|
+
# If there's an exact match a Hash of one element will be returned,
|
130
|
+
# otherwise a sub-Hash with every key that matches the search will
|
131
|
+
# be returned.
|
132
|
+
#
|
133
|
+
# @param [String] search the search term
|
134
|
+
# @param [Hash] hash the hash to search
|
135
|
+
def search_hash(search, hash)
|
136
|
+
matching = {}
|
137
|
+
|
138
|
+
hash.each_pair do |key, value|
|
139
|
+
next unless key.is_a?(String)
|
140
|
+
if normalize(key) == normalize(search)
|
141
|
+
return {key => value}
|
142
|
+
elsif normalize(key).start_with?(normalize(search))
|
143
|
+
matching[key] = value
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
matching
|
148
|
+
end
|
149
|
+
|
150
|
+
# Clean search terms to make it easier to search group names
|
151
|
+
#
|
152
|
+
# @param [String] key
|
153
|
+
# @return [String]
|
154
|
+
def normalize(key)
|
155
|
+
key.downcase.gsub(/pry\W+/, '')
|
156
|
+
end
|
157
|
+
|
158
|
+
def group_sort_key(group_name)
|
159
|
+
[%w(Help Context Editing Introspection Input_and_output Navigating_pry Gems Basic Commands).index(group_name.gsub(' ', '_')) || 99, group_name]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
Pry::Commands.add_command(Pry::Command::Help)
|
164
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
class Pry
|
2
|
+
class Command::Hist < Pry::ClassCommand
|
3
|
+
match 'hist'
|
4
|
+
group 'Editing'
|
5
|
+
description 'Show and replay Readline history.'
|
6
|
+
|
7
|
+
banner <<-'BANNER'
|
8
|
+
Usage: hist [--head|--tail]
|
9
|
+
hist --all
|
10
|
+
hist --head N
|
11
|
+
hist --tail N
|
12
|
+
hist --show START..END
|
13
|
+
hist --grep PATTERN
|
14
|
+
hist --clear
|
15
|
+
hist --replay START..END
|
16
|
+
hist --save [START..END] FILE
|
17
|
+
Aliases: history
|
18
|
+
|
19
|
+
Show and replay Readline history.
|
20
|
+
BANNER
|
21
|
+
|
22
|
+
def options(opt)
|
23
|
+
opt.on :a, :all, "Display all history"
|
24
|
+
opt.on :H, :head, "Display the first N items", :optional_argument => true, :as => Integer
|
25
|
+
opt.on :T, :tail, "Display the last N items", :optional_argument => true, :as => Integer
|
26
|
+
opt.on :s, :show, "Show the given range of lines", :optional_argument => true, :as => Range
|
27
|
+
opt.on :G, :grep, "Show lines matching the given pattern", :argument => true, :as => String
|
28
|
+
opt.on :c, :clear , "Clear the current session's history"
|
29
|
+
opt.on :r, :replay, "Replay a line or range of lines", :argument => true, :as => Range
|
30
|
+
opt.on :save, "Save history to a file", :argument => true, :as => Range
|
31
|
+
opt.on :e, :'exclude-pry', "Exclude Pry commands from the history"
|
32
|
+
opt.on :n, :'no-numbers', "Omit line numbers"
|
33
|
+
end
|
34
|
+
|
35
|
+
def process
|
36
|
+
@history = find_history
|
37
|
+
|
38
|
+
if opts.present?(:show)
|
39
|
+
@history = @history.between(opts[:show])
|
40
|
+
end
|
41
|
+
|
42
|
+
if opts.present?(:grep)
|
43
|
+
@history = @history.grep(opts[:grep])
|
44
|
+
end
|
45
|
+
|
46
|
+
@history = case
|
47
|
+
when opts.present?(:head)
|
48
|
+
@history.take_lines(1, opts[:head] || 10)
|
49
|
+
when opts.present?(:tail)
|
50
|
+
@history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
|
51
|
+
when opts.present?(:show)
|
52
|
+
@history.between(opts[:show])
|
53
|
+
else
|
54
|
+
@history
|
55
|
+
end
|
56
|
+
|
57
|
+
if opts.present?(:'exclude-pry')
|
58
|
+
@history = @history.select do |loc|
|
59
|
+
!command_set.valid_command?(loc.line)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if opts.present?(:save)
|
64
|
+
process_save
|
65
|
+
elsif opts.present?(:clear)
|
66
|
+
process_clear
|
67
|
+
elsif opts.present?(:replay)
|
68
|
+
process_replay
|
69
|
+
else
|
70
|
+
process_display
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def process_display
|
77
|
+
unless opts.present?(:'no-numbers')
|
78
|
+
@history = @history.with_line_numbers
|
79
|
+
end
|
80
|
+
|
81
|
+
_pry_.pager.open do |pager|
|
82
|
+
@history.print_to_output(pager, true)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def process_save
|
87
|
+
case opts[:save]
|
88
|
+
when Range
|
89
|
+
@history = @history.between(opts[:save])
|
90
|
+
|
91
|
+
unless args.first
|
92
|
+
raise CommandError, "Must provide a file name."
|
93
|
+
end
|
94
|
+
|
95
|
+
file_name = File.expand_path(args.first)
|
96
|
+
when String
|
97
|
+
file_name = File.expand_path(opts[:save])
|
98
|
+
end
|
99
|
+
|
100
|
+
output.puts "Saving history in #{file_name}..."
|
101
|
+
|
102
|
+
File.open(file_name, 'w') { |f| f.write(@history.raw) }
|
103
|
+
|
104
|
+
output.puts "History saved."
|
105
|
+
end
|
106
|
+
|
107
|
+
def process_clear
|
108
|
+
Pry.history.clear
|
109
|
+
output.puts "History cleared."
|
110
|
+
end
|
111
|
+
|
112
|
+
def process_replay
|
113
|
+
@history = @history.between(opts[:r])
|
114
|
+
replay_sequence = @history.raw
|
115
|
+
|
116
|
+
# If we met follow-up "hist" call, check for the "--replay" option
|
117
|
+
# presence. If "hist" command is called with other options, proceed
|
118
|
+
# further.
|
119
|
+
check_for_juxtaposed_replay(replay_sequence)
|
120
|
+
|
121
|
+
replay_sequence.lines.each do |line|
|
122
|
+
_pry_.eval line, :generated => true
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Checks +replay_sequence+ for the presence of neighboring replay calls.
|
127
|
+
# @example
|
128
|
+
# [1] pry(main)> hist --show 46894
|
129
|
+
# 46894: hist --replay 46675..46677
|
130
|
+
# [2] pry(main)> hist --show 46675..46677
|
131
|
+
# 46675: 1+1
|
132
|
+
# 46676: a = 100
|
133
|
+
# 46677: hist --tail
|
134
|
+
# [3] pry(main)> hist --replay 46894
|
135
|
+
# Error: Replay index 46894 points out to another replay call: `hist -r 46675..46677`
|
136
|
+
# [4] pry(main)>
|
137
|
+
#
|
138
|
+
# @raise [Pry::CommandError] If +replay_sequence+ contains another
|
139
|
+
# "hist --replay" call
|
140
|
+
# @param [String] replay_sequence The sequence of commands to be replayed
|
141
|
+
# (per saltum)
|
142
|
+
# @return [Boolean] `false` if +replay_sequence+ does not contain another
|
143
|
+
# "hist --replay" call
|
144
|
+
def check_for_juxtaposed_replay(replay_sequence)
|
145
|
+
if replay_sequence =~ /\Ahist(?:ory)?\b/
|
146
|
+
# Create *fresh* instance of Options for parsing of "hist" command.
|
147
|
+
_slop = self.slop
|
148
|
+
_slop.parse replay_sequence.split(' ')[1..-1]
|
149
|
+
|
150
|
+
if _slop.present?(:r)
|
151
|
+
replay_sequence = replay_sequence.split("\n").join('; ')
|
152
|
+
index = opts[:r]
|
153
|
+
index = index.min if index.min == index.max || index.max.nil?
|
154
|
+
|
155
|
+
raise CommandError, "Replay index #{ index } points out to another replay call: `#{ replay_sequence }`"
|
156
|
+
end
|
157
|
+
else
|
158
|
+
false
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
# Finds history depending on the given switch.
|
163
|
+
#
|
164
|
+
# @return [Pry::Code] if it finds `--all` (or `-a`) switch, returns all
|
165
|
+
# entries in history. Without the switch returns only the entries from the
|
166
|
+
# current Pry session.
|
167
|
+
def find_history
|
168
|
+
h = if opts.present?(:all)
|
169
|
+
Pry.history.to_a
|
170
|
+
else
|
171
|
+
Pry.history.to_a.last(Pry.history.session_line_count)
|
172
|
+
end
|
173
|
+
# The last value in history will be the 'hist' command itself.
|
174
|
+
Pry::Code(h[0..-2])
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
Pry::Commands.add_command(Pry::Command::Hist)
|
179
|
+
Pry::Commands.alias_command 'history', 'hist'
|
180
|
+
end
|