@@ -88,7 +88,9 @@ class Core
88
88
@@history_opts = Rex ::Parser ::Arguments . new (
89
89
"-h" => [ false , "Help banner." ] ,
90
90
"-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." ] )
92
94
93
95
@@irb_opts = Rex ::Parser ::Arguments . new (
94
96
"-h" => [ false , "Help banner." ] ,
@@ -480,6 +482,7 @@ def cmd_exit(*args)
480
482
481
483
def cmd_history ( *args )
482
484
length = Readline ::HISTORY . length
485
+ uniq = false
483
486
484
487
if length < @history_limit
485
488
limit = length
@@ -498,6 +501,11 @@ def cmd_history(*args)
498
501
else
499
502
limit = val . to_i
500
503
end
504
+ when "-u"
505
+ uniq = true
506
+ when "-c"
507
+ Readline ::HISTORY . clear
508
+ return
501
509
when "-h"
502
510
cmd_history_help
503
511
return false
@@ -508,6 +516,9 @@ def cmd_history(*args)
508
516
pad_len = length . to_s . length
509
517
510
518
( start ..length -1 ) . each do |pos |
519
+ if uniq && Readline ::HISTORY [ pos ] == Readline ::HISTORY [ pos -1 ]
520
+ next unless pos == 0
521
+ end
511
522
cmd_num = ( pos + 1 ) . to_s
512
523
print_line "#{ cmd_num . ljust ( pad_len ) } #{ Readline ::HISTORY [ pos ] } "
513
524
end
0 commit comments