Skip to content

Commit 73d4543

Browse files
committed
Fix rapid7#7765, additional fixes for history command
1. Really fix crash by restoring default behavior 2. Add whitespace padding to command number 3. Refactor logic a bit for clarity
1 parent 3ff74f0 commit 73d4543

File tree

1 file changed

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

1 file changed

+17
-8
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,28 +479,37 @@ def cmd_exit(*args)
479479
alias cmd_quit cmd_exit
480480

481481
def cmd_history(*args)
482-
return cmd_history_help if args.length == 0
483-
484-
limit = @history_limit
485482
length = Readline::HISTORY.length
486483

487-
@@history_opts.parse(args) do |opt, _idx, val|
484+
if length < @history_limit
485+
limit = length
486+
else
487+
limit = @history_limit
488+
end
489+
490+
@@history_opts.parse(args) do |opt, idx, val|
488491
case opt
489492
when "-a"
490493
limit = length
491494
when "-n"
492495
return cmd_history_help unless val && val.match(/\A[-+]?\d+\z/)
493-
limit = val.to_i
494-
limit = length if limit >= length
496+
if length < val.to_i
497+
limit = length
498+
else
499+
limit = val.to_i
500+
end
495501
when "-h"
496502
cmd_history_help
497503
return false
498504
end
499505
end
500506

501-
start = length - limit
507+
start = length - limit
508+
pad_len = length.to_s.length
509+
502510
(start..length-1).each do |pos|
503-
print "#{pos + 1} #{Readline::HISTORY[pos]}\n"
511+
cmd_num = (pos + 1).to_s
512+
print_line "#{cmd_num.ljust(pad_len)} #{Readline::HISTORY[pos]}"
504513
end
505514
end
506515

0 commit comments

Comments
 (0)