From 6b6191a534ebab5000f515897b31f6f15caaa74b Mon Sep 17 00:00:00 2001 From: William Vu Date: Sun, 5 Aug 2018 14:29:20 -0500 Subject: [PATCH] Land #10423, history deduplication on add Also removes history -u deduplication on print. --- lib/msf/ui/console/command_dispatcher/core.rb | 10 ++-------- lib/rex/ui/text/input/readline.rb | 5 ++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 602e624488..acff7a14c7 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -87,8 +87,7 @@ class Core @@history_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help banner." ], "-a" => [ false, "Show all commands in history." ], - "-n" => [ true, "Show the last n commands." ], - "-u" => [ false, "Show only unique commands." ]) + "-n" => [ true, "Show the last n commands." ]) @@irb_opts = Rex::Parser::Arguments.new( "-h" => [ false, "Help banner." ], @@ -475,7 +474,6 @@ class Core def cmd_history(*args) length = Readline::HISTORY.length - uniq = false if length < @history_limit limit = length @@ -494,8 +492,6 @@ class Core else limit = val.to_i end - when "-u" - uniq = true when "-h" cmd_history_help return false @@ -506,9 +502,6 @@ class Core pad_len = length.to_s.length (start..length-1).each do |pos| - if uniq && Readline::HISTORY[pos] == Readline::HISTORY[pos-1] - next unless pos == 0 - end cmd_num = (pos + 1).to_s print_line "#{cmd_num.ljust(pad_len)} #{Readline::HISTORY[pos]}" end @@ -519,6 +512,7 @@ class Core print_line print_line "Shows the command history." print_line "If -n is not set, only the last #{@history_limit} commands will be shown." + print_line print @@history_opts.usage end diff --git a/lib/rex/ui/text/input/readline.rb b/lib/rex/ui/text/input/readline.rb index 022fd8c6a6..b302faa2e3 100644 --- a/lib/rex/ui/text/input/readline.rb +++ b/lib/rex/ui/text/input/readline.rb @@ -168,7 +168,10 @@ begin end if add_history && line - RbReadline.add_history(line) + # Don't add duplicate lines to history + if ::Readline::HISTORY.empty? || line != ::Readline::HISTORY[-1] + RbReadline.add_history(line) + end end line.try(:dup)