From b02e753dbf5dbe54e4d3fcc67e374a4fe7a91eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Topalovi=C4=87?= Date: Sat, 6 Sep 2025 17:36:12 +0200 Subject: [PATCH 1/2] Do not save consecutive duplicate commands to history --- lib/irb/input-method.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index b9bbdeb1e..2595b9236 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -223,7 +223,7 @@ def gets Readline.input = @stdin Readline.output = @stdout if l = Readline.readline(@prompt, false) - Readline::HISTORY.push(l) if !l.empty? + Readline::HISTORY.push(l) if !l.empty? && l != Readline::HISTORY.last @line[@line_no += 1] = l + "\n" else @eof = true @@ -480,7 +480,7 @@ def gets Reline.prompt_proc = @prompt_proc Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc if l = Reline.readmultiline(@prompt, false, &@check_termination_proc) - Reline::HISTORY.push(l) if !l.empty? + Reline::HISTORY.push(l) if !l.empty? && l != Reline::HISTORY.last @line[@line_no += 1] = l + "\n" else @eof = true From 2640a071c0317a10d7bf2eb4b8c4e963eff43156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Topalovi=C4=87?= Date: Sat, 6 Sep 2025 18:06:54 +0200 Subject: [PATCH 2/2] Cast Readline/Reline history to array to support older versions --- lib/irb/input-method.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 2595b9236..17ed55a50 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -223,7 +223,7 @@ def gets Readline.input = @stdin Readline.output = @stdout if l = Readline.readline(@prompt, false) - Readline::HISTORY.push(l) if !l.empty? && l != Readline::HISTORY.last + Readline::HISTORY.push(l) if !l.empty? && l != Readline::HISTORY.to_a.last @line[@line_no += 1] = l + "\n" else @eof = true @@ -480,7 +480,7 @@ def gets Reline.prompt_proc = @prompt_proc Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc if l = Reline.readmultiline(@prompt, false, &@check_termination_proc) - Reline::HISTORY.push(l) if !l.empty? && l != Reline::HISTORY.last + Reline::HISTORY.push(l) if !l.empty? && l != Reline::HISTORY.to_a.last @line[@line_no += 1] = l + "\n" else @eof = true