Skip to content

Commit 9f0ff3f

Browse files
committed
Add in sort and order options
1 parent 2068514 commit 9f0ff3f

File tree

1 file changed

+18
-5
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+18
-5
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class Console::CommandDispatcher::Stdapi::Fs
5757
# Options for the ls command
5858
#
5959
@@lls_opts = Rex::Parser::Arguments.new(
60-
"-h" => [ false, "Help banner." ])
60+
"-h" => [ false, "Help banner." ],
61+
"-t" => [ false, "Sort by time" ],
62+
"-s" => [ false, "Sort by size" ],
63+
"-r" => [ false, "Reverse sort order" ])
6164

6265
#
6366
# List of supported commands.
@@ -686,12 +689,12 @@ def cmd_lls_help
686689
#
687690
# Get list local path information for lls command
688691
#
689-
def list_local_path(path)
692+
def list_local_path(path, sort, order)
690693
columns = [ 'Mode', 'Size', 'Type', 'Last modified', 'Name' ]
691694
tbl = Rex::Text::Table.new(
692695
'Header' => "Listing Local: #{path}",
693-
'SortIndex' => columns.index("Name"),
694-
'SortOrder' => :forward,
696+
'SortIndex' => columns.index(sort),
697+
'SortOrder' => order,
695698
'Columns' => columns)
696699

697700
items = 0
@@ -740,10 +743,20 @@ def list_local_path(path)
740743
#
741744
def cmd_lls(*args)
742745
path = ::Dir.pwd
746+
sort = 'Name'
747+
order = :forward
743748

744749
# Parse the args
745750
@@lls_opts.parse(args) { |opt, idx, val|
746751
case opt
752+
# Sort options
753+
when '-s'
754+
sort = 'Size'
755+
when '-t'
756+
sort = 'Last modified'
757+
# Output options
758+
when '-r'
759+
order = :reverse
747760
# Help and path
748761
when "-h"
749762
cmd_lls_help
@@ -753,7 +766,7 @@ def cmd_lls(*args)
753766
end
754767
}
755768

756-
list_local_path(path)
769+
list_local_path(path, sort, order)
757770
end
758771

759772
#

0 commit comments

Comments
 (0)