Skip to content

Instantly share code, notes, and snippets.

@xvybihal
Created September 13, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xvybihal/a29232abb5e22f9bb1261771d9371e7c to your computer and use it in GitHub Desktop.
Save xvybihal/a29232abb5e22f9bb1261771d9371e7c to your computer and use it in GitHub Desktop.
└──> $ >> cat /usr/share/perl5/vendor_perl/auto/share/dist/App-Cope/ls
#!/usr/bin/env perl
use App::Cope;
use App::Cope::Extra qw[user %permissions %filetypes];
my $date_re = qr{
(?:\d{4}-)? # year
\d{2} - \d{2} # month-day
\s \d{2}:\d{2} # hour-minute
(?::\d{2}.\d+\s # iso time thing
\+\d{4})?
\b # end on a boundary
}x;
sub size {
# only files have actual file sizes
if ( /^-/ ) {
return 'green bold';
} else {
return 'green';
}
}
my $highlighting = 0;
sub process {
# Check whether we have to highlight at all
if (/^total \d/) {
$highlighting = 1;
mark qr{^.+} => 'underline';
}
# No highlighting when using the -s switch, though
if (/^\s*\d/) {
$highlighting = 0;
}
if ($highlighting) {
my $ts = join '', keys %filetypes;
line qr{([-$ts])(.)(.)(.)(.)(.)(.)(.)(.)(.)[ .+]?\s+(\d+)\s+(\S+)\s*(\S*)\s+([0-9,.]+)([KMG]?)\s} =>
\%filetypes, ( \%permissions ) x 9, 'red',
\&{ user 'yellow' }, 'yellow', \&size, 'green';
mark $date_re => 'green';
}
}
#run( \&process, real_path(), @ARGV );
run( \&process, '/usr/bin/ls', @ARGV );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment