Skip to content

Commit db90d54

Browse files
committed
Add history deduplication and clearing
1 parent 73d4543 commit db90d54

File tree

1 file changed

+12
-1
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ 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." ],
93+
"-c" => [ false, "Clear command history." ])
9294

9395
@@irb_opts = Rex::Parser::Arguments.new(
9496
"-h" => [ false, "Help banner." ],
@@ -480,6 +482,7 @@ def cmd_exit(*args)
480482

481483
def cmd_history(*args)
482484
length = Readline::HISTORY.length
485+
uniq = false
483486

484487
if length < @history_limit
485488
limit = length
@@ -498,6 +501,11 @@ def cmd_history(*args)
498501
else
499502
limit = val.to_i
500503
end
504+
when "-u"
505+
uniq = true
506+
when "-c"
507+
Readline::HISTORY.clear
508+
return
501509
when "-h"
502510
cmd_history_help
503511
return false
@@ -508,6 +516,9 @@ def cmd_history(*args)
508516
pad_len = length.to_s.length
509517

510518
(start..length-1).each do |pos|
519+
if uniq && Readline::HISTORY[pos] == Readline::HISTORY[pos-1]
520+
next unless pos == 0
521+
end
511522
cmd_num = (pos + 1).to_s
512523
print_line "#{cmd_num.ljust(pad_len)} #{Readline::HISTORY[pos]}"
513524
end

0 commit comments

Comments
 (0)