Land #10423, history deduplication on add

Also removes history -u deduplication on print.
4.x
William Vu 2018-08-05 14:29:20 -05:00 committed by Metasploit
parent a67938aab6
commit 6b6191a534
No known key found for this signature in database
GPG Key ID: CDFB5FA52007B954
2 changed files with 6 additions and 9 deletions

View File

@ -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

View File

@ -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)