X-Git-Url: http://git.treefish.org/fex.git/blobdiff_plain/e60096926213ce02293a261254ff065cae44c1c8..20160104:/bin/l diff --git a/bin/l b/bin/l index 1389931..c7d7667 100755 --- a/bin/l +++ b/bin/l @@ -1,10 +1,10 @@ #!/usr/bin/perl -w # -# l / ll / lf / llf - substitute of the classic ls command +# l / ll / lf / llf - better replacement of the classic ls command # # Author: Ulli Horlacher # -# Copyright: GNU General Public License +# Copyright: Perl Artistic License use Cwd qw'abs_path'; use File::Basename; @@ -22,31 +22,24 @@ $ENV{LC_CTYPE} = 'C'; # parse CLI arguments $opt_l = $opt_i = $opt_t = $opt_s = $opt_a = $opt_r = $opt_d = $opt_n = 0; $opt_L = $opt_N = $opt_c = $opt_u = $opt_S = $opt_R = $opt_z = $opt_h = 0; -$opt_U = $opt_x = 0; -${'opt_*'} = ${'opt_?'} = 0; +$opt_U = $opt_x = $opt_E = 0; +${'opt_*'} = 0; $opt_m = $opt_f = $opt_F = $opt_D = ''; -&usage if !getopts('hdnlLNitcuarsxUSRz*?m:f:D:F:') || $opt_h; +getopts('hdnlLNitcuarsxUSREz*m:f:D:F:') or usage(1); +usage(0) if $opt_h; $opt_z = 1 unless $opt_R; $opt_l = 1 if $0 eq 'll'; $opt_l = $opt_i = $opt_a = $opt_S = 1 if $0 eq 'lll'; +&examples if $opt_E; if ($0 eq 'lf' or $0 eq 'llf') { - unless ($opt_F) { - $opt_F = shift; - unless (length $opt_F) { - print "find regexp: "; - chomp($opt_F = ||''); - } - } - $opt_l = $0 if $0 eq 'llf'; - $opt_F = '.' unless length $opt_F; - $opt_R = $opt_F; + $opt_F ||= shift or usage(1); + $opt_R ||= scalar(@ARGV) || ($opt_F eq '.'); + $opt_l ||= $0 eq 'llf'; } $postsort = $opt_t||$opt_s; $postproc = $postsort||$opt_z; -&examples if ${'opt_?'}; - # mark for squeeze operation $z = $opt_z ? "\0" : ''; @@ -551,14 +544,17 @@ sub fmatch { sub usage { + my $status = shift; my $opts = '[-lastcuidnrzLRxNS*] [-f format] [-D X:Y]'; + local *OUT = $status ? *STDERR : *STDOUT; + if ($0 ne 'lf') { - print "usage: $0 $opts [-F regexp] [file...]\n"; + print OUT "usage: $0 $opts [-F regexp] [file...]\n"; } $opts =~ s/R//; - print "usage: lf $opts regexp [directory...]\n"; - print <