Skip to content

Commit 16227dd

Browse files
Save history on exit
1 parent 48b4670 commit 16227dd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/irb.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ def IRB.irb_exit(*)
889889
throw :IRB_EXIT
890890
end
891891

892+
def IRB.irb_exit!(*)
893+
throw :IRB_EXIT
894+
end
895+
892896
# Aborts then interrupts irb.
893897
#
894898
# Will raise an Abort exception, or the given +exception+.

lib/irb/cmd/exit_forced_action.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "nop"
4+
5+
module IRB
6+
# :stopdoc:
7+
8+
module ExtendCommand
9+
class ExitForcedAction < Nop
10+
category "IRB"
11+
description "Exit the current irb session with exit!."
12+
13+
def execute(*)
14+
IRB.irb_exit!
15+
rescue UncaughtThrowError
16+
Kernel.exit
17+
end
18+
end
19+
end
20+
21+
# :startdoc:
22+
end

lib/irb/extend-command.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def irb_context
3636
[:quit, OVERRIDE_PRIVATE_ONLY],
3737
[:irb_quit, OVERRIDE_PRIVATE_ONLY],
3838
],
39+
[
40+
:irb_exit!, :ExitForcedAction, "cmd/exit_forced_action",
41+
[:exit!, OVERRIDE_PRIVATE_ONLY],
42+
],
43+
3944
[
4045
:irb_current_working_workspace, :CurrentWorkingWorkspace, "cmd/chws",
4146
[:cwws, NO_OVERRIDE],

0 commit comments

Comments
 (0)