Land #10423, history deduplication on add

Also removes history -u deduplication on print.
GSoC/Meterpreter_Web_Console
William Vu 2018-08-05 14:29:20 -05:00
commit b21d73a170
No known key found for this signature in database
GPG Key ID: 68BD00CE25866743
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." ],
@ -470,7 +469,6 @@ class Core
def cmd_history(*args)
length = Readline::HISTORY.length
uniq = false
if length < @history_limit
limit = length
@ -489,8 +487,6 @@ class Core
else
limit = val.to_i
end
when "-u"
uniq = true
when "-h"
cmd_history_help
return false
@ -501,9 +497,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
@ -514,6 +507,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)