Skip to content

Commit b94eefe

Browse files
author
Brent Cook
committed
Land rapid7#7771, Add history deduplication
2 parents 7f6b403 + ef487f6 commit b94eefe

File tree

1 file changed

+8
-2
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+8
-2
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class Core
8888
@@history_opts = Rex::Parser::Arguments.new(
8989
"-h" => [ false, "Help banner." ],
9090
"-a" => [ false, "Show all commands in history." ],
91-
"-n" => [ true, "Show the last n commands." ])
91+
"-n" => [ true, "Show the last n commands." ],
92+
"-u" => [ false, "Show only unique commands." ])
9293

9394
@@irb_opts = Rex::Parser::Arguments.new(
9495
"-h" => [ false, "Help banner." ],
@@ -480,6 +481,7 @@ def cmd_exit(*args)
480481

481482
def cmd_history(*args)
482483
length = Readline::HISTORY.length
484+
uniq = false
483485

484486
if length < @history_limit
485487
limit = length
@@ -498,6 +500,8 @@ def cmd_history(*args)
498500
else
499501
limit = val.to_i
500502
end
503+
when "-u"
504+
uniq = true
501505
when "-h"
502506
cmd_history_help
503507
return false
@@ -508,6 +512,9 @@ def cmd_history(*args)
508512
pad_len = length.to_s.length
509513

510514
(start..length-1).each do |pos|
515+
if uniq && Readline::HISTORY[pos] == Readline::HISTORY[pos-1]
516+
next unless pos == 0
517+
end
511518
cmd_num = (pos + 1).to_s
512519
print_line "#{cmd_num.ljust(pad_len)} #{Readline::HISTORY[pos]}"
513520
end
@@ -518,7 +525,6 @@ def cmd_history_help
518525
print_line
519526
print_line "Shows the command history."
520527
print_line "If -n is not set, only the last #{@history_limit} commands will be shown."
521-
print_line
522528
print @@history_opts.usage
523529
end
524530

0 commit comments

Comments
 (0)