Skip to content

Commit 3ff74f0

Browse files
committed
Fix rapid7#7765, history command fixes and improvements
1. Fix crash when no arguments are specified 2. Print history index starting at 1 like every shell 3. Fixed wording/phrasing 4. Fixed formatting/whitespace
1 parent c2fec5d commit 3ff74f0

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

features/commands/help.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Feature: Help command
2121
getg Gets the value of a global variable
2222
grep Grep the output of another command
2323
help Help menu
24-
history Show commands history
24+
history Show command history
2525
irb Drop into irb scripting mode
2626
load Load a framework plugin
2727
quit Exit the console

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ 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." ])
9292

9393
@@irb_opts = Rex::Parser::Arguments.new(
9494
"-h" => [ false, "Help banner." ],
@@ -108,7 +108,7 @@ def commands
108108
"getg" => "Gets the value of a global variable",
109109
"grep" => "Grep the output of another command",
110110
"help" => "Help menu",
111-
"history" => "Show commands history",
111+
"history" => "Show command history",
112112
"irb" => "Drop into irb scripting mode",
113113
"load" => "Load a framework plugin",
114114
"quit" => "Exit the console",
@@ -478,18 +478,18 @@ def cmd_exit(*args)
478478

479479
alias cmd_quit cmd_exit
480480

481-
482481
def cmd_history(*args)
483-
482+
return cmd_history_help if args.length == 0
483+
484484
limit = @history_limit
485-
length = Readline::HISTORY.length
485+
length = Readline::HISTORY.length
486486

487487
@@history_opts.parse(args) do |opt, _idx, val|
488488
case opt
489489
when "-a"
490490
limit = length
491491
when "-n"
492-
return cmd_history_help unless !val.nil? && val.match(/\A[-+]?\d+\z/)
492+
return cmd_history_help unless val && val.match(/\A[-+]?\d+\z/)
493493
limit = val.to_i
494494
limit = length if limit >= length
495495
when "-h"
@@ -498,23 +498,21 @@ def cmd_history(*args)
498498
end
499499
end
500500

501-
start = length - limit
501+
start = length - limit
502502
(start..length-1).each do |pos|
503-
print "#{pos} #{Readline::HISTORY[pos]}\n"
503+
print "#{pos + 1} #{Readline::HISTORY[pos]}\n"
504504
end
505505
end
506506

507507
def cmd_history_help
508508
print_line "Usage: history [options]"
509509
print_line
510510
print_line "Shows the command history."
511-
print_line "If -n is not set, it will only be shown the last #{@history_limit} commands."
511+
print_line "If -n is not set, only the last #{@history_limit} commands will be shown."
512512
print_line
513513
print @@history_opts.usage
514514
end
515515

516-
517-
518516
def cmd_sleep_help
519517
print_line "Usage: sleep <seconds>"
520518
print_line

0 commit comments

Comments
 (0)