-
Notifications
You must be signed in to change notification settings - Fork 6
/
color_ls.cna
43 lines (37 loc) · 1.34 KB
/
color_ls.cna
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
set BEACON_OUTPUT_LS {
local('$out @results $cwd $entry $type $size $modified $name');
@results = split("\n", ["$2" trim]);
$cwd = left(shift(@results), -1); # first entry is the current folder
# parse/process results
foreach $entry (@results) {
($type, $size, $modified, $name) = split("\t", $entry);
if ($type eq "F") {
$entry = %(type => "fil", size => format_size($size), modified => $modified, name => $name);
}
else if ($type eq "D" && $name ne "." && $name ne "..") {
$entry = %(type => "dir", size => "", modified => $modified, name => $name);
}
else {
remove();
}
}
# sort in alpha order with dir listings on top.
sort({ return ($1['type'] . lc($1['name'])) cmp ($2['type'] . lc($2['name'])); }, @results);
$out .= "\cC[*]\o Listing: $cwd $+ \n\n";
$out .= " Size Type Last Modified Name\n";
$out .= "\cE ---- ---- ------------- ----\n";
foreach $entry (@results) {
($type, $size, $modified, $name) = values($entry, @('type', 'size', 'modified', 'name'));
if ($type eq 'dir') {
# color orange
$color = "\c7";
} else if ($name ismatch '.*\.exe' || $name ismatch '.*\.ps1' || $name ismatch '.*\.bat' || $name ismatch '.*\.cmd') {
# color green
$color = "\c3";
} else {
$color = '';
}
$out .= " $[8]size $[7]type $[21]modified$color $name $+ \n";
}
return $out;
}