X-Git-Url: http://git.treefish.org/fex.git/blobdiff_plain/7fa382617fbaccc0ce522b2b3adbbee9db5ad227..c65ee6f7429eff9a7f58aad7c0aec858ad473092:/bin/l?ds=inline diff --git a/bin/l b/bin/l index 93c4aca..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 = 0; -${'opt_*'} = ${'opt_?'} = 0; +$opt_U = $opt_x = $opt_E = 0; +${'opt_*'} = 0; $opt_m = $opt_f = $opt_F = $opt_D = ''; -&usage if !getopts('hdnlLNitcuarsUSRz*?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" : ''; @@ -167,6 +160,12 @@ sub collect { # traverse real subdirs if (-d $f and not -l $f) { $f =~ s:/*$:/:; + # skip other file systems on -x + if ($opt_x) { + my @pd = stat(dirname($f)); + my @sd = stat($f); + next if $pd[0] ne $sd[0]; + } collect(getfiles($f)); } @@ -545,14 +544,17 @@ sub fmatch { sub usage { - my $opts = '[-lastcuidnrzLRNS*] [-f format] [-D X:Y]'; + 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 <