irb 1.8.3 → 1.13.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.
- checksums.yaml +4 -4
- data/.document +1 -1
- data/Gemfile +9 -1
- data/README.md +149 -25
- data/Rakefile +13 -3
- data/irb.gemspec +2 -2
- data/lib/irb/cmd/nop.rb +3 -52
- data/lib/irb/color.rb +2 -2
- data/lib/irb/command/backtrace.rb +17 -0
- data/lib/irb/command/base.rb +62 -0
- data/lib/irb/command/break.rb +17 -0
- data/lib/irb/command/catch.rb +17 -0
- data/lib/irb/command/chws.rb +40 -0
- data/lib/irb/command/context.rb +16 -0
- data/lib/irb/{cmd → command}/continue.rb +3 -3
- data/lib/irb/{cmd → command}/debug.rb +11 -20
- data/lib/irb/{cmd → command}/delete.rb +3 -3
- data/lib/irb/command/disable_irb.rb +19 -0
- data/lib/irb/command/edit.rb +63 -0
- data/lib/irb/command/exit.rb +18 -0
- data/lib/irb/{cmd → command}/finish.rb +3 -3
- data/lib/irb/command/force_exit.rb +18 -0
- data/lib/irb/command/help.rb +83 -0
- data/lib/irb/command/history.rb +45 -0
- data/lib/irb/command/info.rb +17 -0
- data/lib/irb/command/internal_helpers.rb +27 -0
- data/lib/irb/{cmd → command}/irb_info.rb +7 -7
- data/lib/irb/{cmd → command}/load.rb +23 -8
- data/lib/irb/{cmd → command}/ls.rb +30 -14
- data/lib/irb/{cmd → command}/measure.rb +18 -17
- data/lib/irb/{cmd → command}/next.rb +3 -3
- data/lib/irb/command/pushws.rb +65 -0
- data/lib/irb/command/show_doc.rb +51 -0
- data/lib/irb/command/show_source.rb +74 -0
- data/lib/irb/{cmd → command}/step.rb +3 -3
- data/lib/irb/{cmd → command}/subirb.rb +31 -17
- data/lib/irb/{cmd → command}/whereami.rb +3 -5
- data/lib/irb/command.rb +23 -0
- data/lib/irb/completion.rb +74 -31
- data/lib/irb/context.rb +144 -57
- data/lib/irb/debug.rb +18 -0
- data/lib/irb/default_commands.rb +260 -0
- data/lib/irb/easter-egg.rb +16 -6
- data/lib/irb/ext/change-ws.rb +6 -8
- data/lib/irb/ext/eval_history.rb +3 -3
- data/lib/irb/ext/loader.rb +4 -4
- data/lib/irb/ext/multi-irb.rb +5 -5
- data/lib/irb/ext/tracer.rb +12 -51
- data/lib/irb/ext/use-loader.rb +6 -8
- data/lib/irb/ext/workspaces.rb +10 -34
- data/lib/irb/frame.rb +1 -1
- data/lib/irb/help.rb +3 -3
- data/lib/irb/helper_method/base.rb +16 -0
- data/lib/irb/helper_method/conf.rb +11 -0
- data/lib/irb/helper_method.rb +29 -0
- data/lib/irb/history.rb +15 -4
- data/lib/irb/init.rb +119 -52
- data/lib/irb/input-method.rb +77 -27
- data/lib/irb/inspector.rb +3 -3
- data/lib/irb/lc/error.rb +1 -11
- data/lib/irb/lc/help-message +4 -0
- data/lib/irb/lc/ja/error.rb +1 -11
- data/lib/irb/lc/ja/help-message +13 -0
- data/lib/irb/locale.rb +2 -2
- data/lib/irb/nesting_parser.rb +13 -3
- data/lib/irb/notifier.rb +1 -1
- data/lib/irb/output-method.rb +2 -8
- data/lib/irb/pager.rb +16 -11
- data/lib/irb/ruby-lex.rb +2 -2
- data/lib/irb/ruby_logo.aa +43 -0
- data/lib/irb/source_finder.rb +112 -37
- data/lib/irb/statement.rb +24 -24
- data/lib/irb/version.rb +3 -3
- data/lib/irb/workspace.rb +22 -6
- data/lib/irb/ws-for-case-2.rb +1 -1
- data/lib/irb/xmp.rb +3 -3
- data/lib/irb.rb +1071 -556
- data/man/irb.1 +7 -0
- metadata +41 -31
- data/lib/irb/cmd/backtrace.rb +0 -21
- data/lib/irb/cmd/break.rb +0 -21
- data/lib/irb/cmd/catch.rb +0 -21
- data/lib/irb/cmd/chws.rb +0 -36
- data/lib/irb/cmd/edit.rb +0 -60
- data/lib/irb/cmd/help.rb +0 -23
- data/lib/irb/cmd/info.rb +0 -21
- data/lib/irb/cmd/pushws.rb +0 -45
- data/lib/irb/cmd/show_cmds.rb +0 -53
- data/lib/irb/cmd/show_doc.rb +0 -48
- data/lib/irb/cmd/show_source.rb +0 -61
- data/lib/irb/extend-command.rb +0 -354
data/lib/irb/ext/change-ws.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# irb/ext/cb.rb -
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
|
@@ -12,7 +12,7 @@ module IRB # :nodoc:
|
|
|
12
12
|
if defined? @home_workspace
|
|
13
13
|
@home_workspace
|
|
14
14
|
else
|
|
15
|
-
@home_workspace =
|
|
15
|
+
@home_workspace = workspace
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -25,15 +25,13 @@ module IRB # :nodoc:
|
|
|
25
25
|
# See IRB::WorkSpace.new for more information.
|
|
26
26
|
def change_workspace(*_main)
|
|
27
27
|
if _main.empty?
|
|
28
|
-
|
|
28
|
+
replace_workspace(home_workspace)
|
|
29
29
|
return main
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
main.extend ExtendCommandBundle
|
|
36
|
-
end
|
|
32
|
+
workspace = WorkSpace.new(_main[0])
|
|
33
|
+
replace_workspace(workspace)
|
|
34
|
+
workspace.load_helper_methods_to_main
|
|
37
35
|
end
|
|
38
36
|
end
|
|
39
37
|
end
|
data/lib/irb/ext/eval_history.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# history.rb -
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
|
@@ -18,7 +18,7 @@ module IRB # :nodoc:
|
|
|
18
18
|
|
|
19
19
|
if defined?(@eval_history) && @eval_history
|
|
20
20
|
@eval_history_values.push @line_no, @last_value
|
|
21
|
-
|
|
21
|
+
workspace.evaluate "__ = IRB.CurrentContext.instance_eval{@eval_history_values}"
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
@last_value
|
|
@@ -49,7 +49,7 @@ module IRB # :nodoc:
|
|
|
49
49
|
else
|
|
50
50
|
@eval_history_values = EvalHistory.new(no)
|
|
51
51
|
IRB.conf[:__TMP__EHV__] = @eval_history_values
|
|
52
|
-
|
|
52
|
+
workspace.evaluate("__ = IRB.conf[:__TMP__EHV__]")
|
|
53
53
|
IRB.conf.delete(:__TMP_EHV__)
|
|
54
54
|
end
|
|
55
55
|
else
|
data/lib/irb/ext/loader.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# loader.rb -
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
|
@@ -98,13 +98,13 @@ module IRB # :nodoc:
|
|
|
98
98
|
|
|
99
99
|
def old # :nodoc:
|
|
100
100
|
back_io = @io
|
|
101
|
-
back_path =
|
|
101
|
+
back_path = irb_path
|
|
102
102
|
back_name = @irb_name
|
|
103
103
|
back_scanner = @irb.scanner
|
|
104
104
|
begin
|
|
105
105
|
@io = FileInputMethod.new(path)
|
|
106
106
|
@irb_name = File.basename(path)
|
|
107
|
-
|
|
107
|
+
self.irb_path = path
|
|
108
108
|
@irb.signal_status(:IN_LOAD) do
|
|
109
109
|
if back_io.kind_of?(FileInputMethod)
|
|
110
110
|
@irb.eval_input
|
|
@@ -119,7 +119,7 @@ module IRB # :nodoc:
|
|
|
119
119
|
ensure
|
|
120
120
|
@io = back_io
|
|
121
121
|
@irb_name = back_name
|
|
122
|
-
|
|
122
|
+
self.irb_path = back_path
|
|
123
123
|
@irb.scanner = back_scanner
|
|
124
124
|
end
|
|
125
125
|
end
|
data/lib/irb/ext/multi-irb.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# irb/multi-irb.rb - multiple irb module
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
|
5
5
|
#
|
|
6
6
|
|
|
7
7
|
module IRB
|
|
8
|
-
class JobManager
|
|
8
|
+
class JobManager # :nodoc:
|
|
9
9
|
|
|
10
10
|
# Creates a new JobManager object
|
|
11
11
|
def initialize
|
|
@@ -166,12 +166,12 @@ module IRB
|
|
|
166
166
|
@JobManager = JobManager.new
|
|
167
167
|
|
|
168
168
|
# The current JobManager in the session
|
|
169
|
-
def IRB.JobManager
|
|
169
|
+
def IRB.JobManager # :nodoc:
|
|
170
170
|
@JobManager
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
# The current Context in this session
|
|
174
|
-
def IRB.CurrentContext
|
|
174
|
+
def IRB.CurrentContext # :nodoc:
|
|
175
175
|
IRB.JobManager.irb(Thread.current).context
|
|
176
176
|
end
|
|
177
177
|
|
|
@@ -179,7 +179,7 @@ module IRB
|
|
|
179
179
|
#
|
|
180
180
|
# The optional +file+ argument is given to Context.new, along with the
|
|
181
181
|
# workspace created with the remaining arguments, see WorkSpace.new
|
|
182
|
-
def IRB.irb(file = nil, *main)
|
|
182
|
+
def IRB.irb(file = nil, *main) # :nodoc:
|
|
183
183
|
workspace = WorkSpace.new(*main)
|
|
184
184
|
parent_thread = Thread.current
|
|
185
185
|
Thread.start do
|
data/lib/irb/ext/tracer.rb
CHANGED
|
@@ -1,78 +1,39 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# irb/lib/tracer.rb -
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
|
5
5
|
#
|
|
6
|
-
|
|
6
|
+
# Loading the gem "tracer" will cause it to extend IRB commands with:
|
|
7
|
+
# https://github.com/ruby/tracer/blob/v0.2.2/lib/tracer/irb.rb
|
|
7
8
|
begin
|
|
8
9
|
require "tracer"
|
|
9
10
|
rescue LoadError
|
|
10
11
|
$stderr.puts "Tracer extension of IRB is enabled but tracer gem wasn't found."
|
|
11
|
-
module IRB
|
|
12
|
-
class Context
|
|
13
|
-
def use_tracer=(opt)
|
|
14
|
-
# do nothing
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
12
|
return # This is about to disable loading below
|
|
19
13
|
end
|
|
20
14
|
|
|
21
15
|
module IRB
|
|
16
|
+
class CallTracer < ::CallTracer
|
|
17
|
+
IRB_DIR = File.expand_path('../..', __dir__)
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Tracer.verbose = false
|
|
26
|
-
Tracer.add_filter {
|
|
27
|
-
|event, file, line, id, binding, *rests|
|
|
28
|
-
/^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
|
|
29
|
-
File::basename(file) != "irb.rb"
|
|
30
|
-
}
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class Context
|
|
34
|
-
# Whether Tracer is used when evaluating statements in this context.
|
|
35
|
-
#
|
|
36
|
-
# See +lib/tracer.rb+ for more information.
|
|
37
|
-
attr_reader :use_tracer
|
|
38
|
-
alias use_tracer? use_tracer
|
|
39
|
-
|
|
40
|
-
# Sets whether or not to use the Tracer library when evaluating statements
|
|
41
|
-
# in this context.
|
|
42
|
-
#
|
|
43
|
-
# See +lib/tracer.rb+ for more information.
|
|
44
|
-
def use_tracer=(opt)
|
|
45
|
-
if opt
|
|
46
|
-
Tracer.set_get_line_procs(@irb_path) {
|
|
47
|
-
|line_no, *rests|
|
|
48
|
-
@io.line(line_no)
|
|
49
|
-
}
|
|
50
|
-
elsif !opt && @use_tracer
|
|
51
|
-
Tracer.off
|
|
52
|
-
end
|
|
53
|
-
@use_tracer=opt
|
|
19
|
+
def skip?(tp)
|
|
20
|
+
super || tp.path.match?(IRB_DIR) || tp.path.match?('<internal:prelude>')
|
|
54
21
|
end
|
|
55
22
|
end
|
|
56
|
-
|
|
57
23
|
class WorkSpace
|
|
58
24
|
alias __evaluate__ evaluate
|
|
59
25
|
# Evaluate the context of this workspace and use the Tracer library to
|
|
60
26
|
# output the exact lines of code are being executed in chronological order.
|
|
61
27
|
#
|
|
62
|
-
# See
|
|
63
|
-
def evaluate(
|
|
64
|
-
if
|
|
65
|
-
|
|
66
|
-
begin
|
|
28
|
+
# See https://github.com/ruby/tracer for more information.
|
|
29
|
+
def evaluate(statements, file = __FILE__, line = __LINE__)
|
|
30
|
+
if IRB.conf[:USE_TRACER] == true
|
|
31
|
+
CallTracer.new(colorize: Color.colorable?).start do
|
|
67
32
|
__evaluate__(statements, file, line)
|
|
68
|
-
ensure
|
|
69
|
-
Tracer.off
|
|
70
33
|
end
|
|
71
34
|
else
|
|
72
|
-
__evaluate__(statements, file
|
|
35
|
+
__evaluate__(statements, file, line)
|
|
73
36
|
end
|
|
74
37
|
end
|
|
75
38
|
end
|
|
76
|
-
|
|
77
|
-
IRB.initialize_tracer
|
|
78
39
|
end
|
data/lib/irb/ext/use-loader.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# use-loader.rb -
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
|
5
5
|
#
|
|
6
6
|
|
|
7
|
-
require_relative "../
|
|
7
|
+
require_relative "../command/load"
|
|
8
8
|
require_relative "loader"
|
|
9
9
|
|
|
10
10
|
class Object
|
|
@@ -17,12 +17,12 @@ module IRB
|
|
|
17
17
|
remove_method :irb_load if method_defined?(:irb_load)
|
|
18
18
|
# Loads the given file similarly to Kernel#load, see IrbLoader#irb_load
|
|
19
19
|
def irb_load(*opts, &b)
|
|
20
|
-
|
|
20
|
+
Command::Load.execute(irb_context, *opts, &b)
|
|
21
21
|
end
|
|
22
22
|
remove_method :irb_require if method_defined?(:irb_require)
|
|
23
23
|
# Loads the given file similarly to Kernel#require
|
|
24
24
|
def irb_require(*opts, &b)
|
|
25
|
-
|
|
25
|
+
Command::Require.execute(irb_context, *opts, &b)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
@@ -49,14 +49,12 @@ module IRB
|
|
|
49
49
|
if IRB.conf[:USE_LOADER] != opt
|
|
50
50
|
IRB.conf[:USE_LOADER] = opt
|
|
51
51
|
if opt
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
(class<<@workspace.main;self;end).instance_eval {
|
|
52
|
+
(class<<workspace.main;self;end).instance_eval {
|
|
55
53
|
alias_method :load, :irb_load
|
|
56
54
|
alias_method :require, :irb_require
|
|
57
55
|
}
|
|
58
56
|
else
|
|
59
|
-
(class
|
|
57
|
+
(class<<workspace.main;self;end).instance_eval {
|
|
60
58
|
alias_method :load, :__original__load__IRB_use_loader__
|
|
61
59
|
alias_method :require, :__original__require__IRB_use_loader__
|
|
62
60
|
}
|
data/lib/irb/ext/workspaces.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# push-ws.rb -
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
|
@@ -6,21 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
module IRB # :nodoc:
|
|
8
8
|
class Context
|
|
9
|
-
|
|
10
|
-
# Size of the current WorkSpace stack
|
|
11
|
-
def irb_level
|
|
12
|
-
workspace_stack.size
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# WorkSpaces in the current stack
|
|
16
|
-
def workspaces
|
|
17
|
-
if defined? @workspaces
|
|
18
|
-
@workspaces
|
|
19
|
-
else
|
|
20
|
-
@workspaces = []
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
9
|
# Creates a new workspace with the given object or binding, and appends it
|
|
25
10
|
# onto the current #workspaces stack.
|
|
26
11
|
#
|
|
@@ -28,20 +13,15 @@ module IRB # :nodoc:
|
|
|
28
13
|
# information.
|
|
29
14
|
def push_workspace(*_main)
|
|
30
15
|
if _main.empty?
|
|
31
|
-
if
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
if @workspace_stack.size > 1
|
|
17
|
+
# swap the top two workspaces
|
|
18
|
+
previous_workspace, current_workspace = @workspace_stack.pop(2)
|
|
19
|
+
@workspace_stack.push current_workspace, previous_workspace
|
|
34
20
|
end
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
workspaces.push @workspace
|
|
42
|
-
@workspace = WorkSpace.new(@workspace.binding, _main[0])
|
|
43
|
-
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
|
44
|
-
main.extend ExtendCommandBundle
|
|
21
|
+
else
|
|
22
|
+
new_workspace = WorkSpace.new(workspace.binding, _main[0])
|
|
23
|
+
@workspace_stack.push new_workspace
|
|
24
|
+
new_workspace.load_helper_methods_to_main
|
|
45
25
|
end
|
|
46
26
|
end
|
|
47
27
|
|
|
@@ -50,11 +30,7 @@ module IRB # :nodoc:
|
|
|
50
30
|
#
|
|
51
31
|
# Also, see #push_workspace.
|
|
52
32
|
def pop_workspace
|
|
53
|
-
if
|
|
54
|
-
print "workspace stack empty\n"
|
|
55
|
-
return
|
|
56
|
-
end
|
|
57
|
-
@workspace = workspaces.pop
|
|
33
|
+
@workspace_stack.pop if @workspace_stack.size > 1
|
|
58
34
|
end
|
|
59
35
|
end
|
|
60
36
|
end
|
data/lib/irb/frame.rb
CHANGED
data/lib/irb/help.rb
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# frozen_string_literal:
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
#
|
|
3
3
|
# irb/help.rb - print usage module
|
|
4
4
|
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
|
|
5
5
|
#
|
|
6
6
|
|
|
7
7
|
module IRB
|
|
8
|
-
# Outputs the irb help message, see IRB@Command+
|
|
9
|
-
def IRB.print_usage
|
|
8
|
+
# Outputs the irb help message, see IRB@Command-Line+Options.
|
|
9
|
+
def IRB.print_usage # :nodoc:
|
|
10
10
|
lc = IRB.conf[:LC_MESSAGES]
|
|
11
11
|
path = lc.find("irb/help-message")
|
|
12
12
|
space_line = false
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative "helper_method/base"
|
|
2
|
+
|
|
3
|
+
module IRB
|
|
4
|
+
module HelperMethod
|
|
5
|
+
@helper_methods = {}
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
attr_reader :helper_methods
|
|
9
|
+
|
|
10
|
+
def register(name, helper_class)
|
|
11
|
+
@helper_methods[name] = helper_class
|
|
12
|
+
|
|
13
|
+
if defined?(HelpersContainer)
|
|
14
|
+
HelpersContainer.install_helper_methods
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def all_helper_methods_info
|
|
19
|
+
@helper_methods.map do |name, helper_class|
|
|
20
|
+
{ display_name: name, description: helper_class.description }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Default helper_methods
|
|
26
|
+
require_relative "helper_method/conf"
|
|
27
|
+
register(:conf, HelperMethod::Conf)
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/irb/history.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require "pathname"
|
|
2
|
+
|
|
1
3
|
module IRB
|
|
2
4
|
module HistorySavingAbility # :nodoc:
|
|
3
5
|
def support_history_saving?
|
|
@@ -5,7 +7,7 @@ module IRB
|
|
|
5
7
|
end
|
|
6
8
|
|
|
7
9
|
def reset_history_counter
|
|
8
|
-
@loaded_history_lines = self.class::HISTORY.size
|
|
10
|
+
@loaded_history_lines = self.class::HISTORY.size
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def load_history
|
|
@@ -15,7 +17,7 @@ module IRB
|
|
|
15
17
|
history_file = File.expand_path(history_file)
|
|
16
18
|
end
|
|
17
19
|
history_file = IRB.rc_file("_history") unless history_file
|
|
18
|
-
if File.exist?(history_file)
|
|
20
|
+
if history_file && File.exist?(history_file)
|
|
19
21
|
File.open(history_file, "r:#{IRB.conf[:LC_MESSAGES].encoding}") do |f|
|
|
20
22
|
f.each { |l|
|
|
21
23
|
l = l.chomp
|
|
@@ -41,6 +43,9 @@ module IRB
|
|
|
41
43
|
end
|
|
42
44
|
history_file = IRB.rc_file("_history") unless history_file
|
|
43
45
|
|
|
46
|
+
# When HOME and XDG_CONFIG_HOME are not available, history_file might be nil
|
|
47
|
+
return unless history_file
|
|
48
|
+
|
|
44
49
|
# Change the permission of a file that already exists[BUG #7694]
|
|
45
50
|
begin
|
|
46
51
|
if File.stat(history_file).mode & 066 != 0
|
|
@@ -59,13 +64,19 @@ module IRB
|
|
|
59
64
|
append_history = true
|
|
60
65
|
end
|
|
61
66
|
|
|
67
|
+
pathname = Pathname.new(history_file)
|
|
68
|
+
unless Dir.exist?(pathname.dirname)
|
|
69
|
+
warn "Warning: The directory to save IRB's history file does not exist. Please double check `IRB.conf[:HISTORY_FILE]`'s value."
|
|
70
|
+
return
|
|
71
|
+
end
|
|
72
|
+
|
|
62
73
|
File.open(history_file, (append_history ? 'a' : 'w'), 0o600, encoding: IRB.conf[:LC_MESSAGES]&.encoding) do |f|
|
|
63
|
-
hist = history.map{ |l| l.split("\n").join("\\\n") }
|
|
74
|
+
hist = history.map{ |l| l.scrub.split("\n").join("\\\n") }
|
|
64
75
|
unless append_history
|
|
65
76
|
begin
|
|
66
77
|
hist = hist.last(num) if hist.size > num and num > 0
|
|
67
78
|
rescue RangeError # bignum too big to convert into `long'
|
|
68
|
-
# Do nothing because the bignum should be treated as
|
|
79
|
+
# Do nothing because the bignum should be treated as infinity
|
|
69
80
|
end
|
|
70
81
|
end
|
|
71
82
|
f.puts(hist)
|