[alt.sources] cl[fs] - print compressed directory listings

jimmy@pyrltd.UUCP (Jimmy Aitken) (01/15/90)

Theis is a conversion of a shell script that I use quite often to list
directories with long filenames in it.  It originally was a shell
script which I converted to perl for speed.  If anyone can suggest
improvements, I'm willing to listen. 

I've lost who posted the original version, but the RCS header on my
copy was: "$Header: cls,v 1.2 88/02/03 14:21:20 jerryp Exp $"
so if that is you my aplogies for not giving full attribution.

Link cls to cls2 clf2 and clf for all the options.
------------------------------CUT-HERE------------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  cls
# Wrapped by jimmy@pyrrot on Mon Jan 15 13:05:27 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'cls' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cls'\"
else
echo shar: Extracting \"'cls'\" \(1968 characters\)
sed "s/^X//" >'cls' <<'END_OF_FILE'
X#!/usr/local/bin/perl
X#	"clf","cls","clf2","cls2" - 
X#		compressed "ls" and "ls -F" directory listings
X#	Usage: cmd [dirs]
X#
X#	"clf", "cls", "clf2", and "cls2" are substitutes for ls -f and ls.
X#	they make compressed listings of the directory.  names longer
X#	than 14 characters are truncated like this:
X#		- on all regular files (not executable, directories, etc.),
X#		  the 14th and succeeding characters are replaced with a ">".
X#		- when using "clf" and "clf2": executable files, directories,
X#		  etc. with names longer than 13 characters... the 13th
X#		  character is replaced with ">", and the 14th character
X#		  will be a * for executable files, / for directories, etc.
X#
X#	"cls" and "clf" list files alphabetically down screen, like ls does:
X#		a       d       k       p       s
X#		b       j       n       r       z
X#	"cls2" and "clf2" list them alphabetically across the screen:
X#		a       b       d       j       k
X#		n       p       r       s       z
X
X
X$pr='|pr -5 -t -w78';
X$comm="ls -F1 @ARGV |"	if $0=~/clf2$/;
X$comm="ls -1 @ARGV |"	if $0=~/cls2$/;
X$comm="ls -F1 @ARGV |"	if $0=~/clf$/;
X$comm="ls -1 @ARGV |"	if $0=~/cls$/;
X$across=1 if $0=~/2$/;			# Sorting across the screen
X
Xopen(PIPE,$comm);
Xopen(OUT,$pr." -l1") if $across;	# pr does this easily for us
Xwhile(<PIPE>) {
X# If line is over 14 characters and ends with symbol "*", "/", "@", OR "="
X# truncate after 12 and replace with >symbol...
X# otherwise, if name is over 14 characters, truncate after 13; add a ">"
X
X    s/^(............)...*([\/@*=][\/@*=]*)$/$1>$2/ if /[\/@*=]$/;
X    s/^(.............)...*/$1>/;
X    if ($across) {
X	print OUT;
X    } else {
X	push(@line,$_);
X    }
X}
Xclose(PIPE);
Xif ($across) {
X    close(OUT);
X    exit(0);
X}
X
X# These commands only done by cls and clf.
X# length of listing = ( number of files / 5 ) + 1, use as ar angument to 'pr'
X$length=int($#line/5)+1;
X$comm="$pr -l$length";
Xopen(PIPE,$comm);
Xwhile ($_=shift(@line)) {
X    print PIPE;
X}
Xclose(PIPE);
Xexit(0);
END_OF_FILE
if test 1968 -ne `wc -c <'cls'`; then
    echo shar: \"'cls'\" unpacked with wrong size!
fi
chmod +x 'cls'
echo "Remember to link cls to clf, cls2 and clf"
# end of 'cls'
fi
echo shar: End of shell archive.
exit 0
-- 
      -m-------  Jimmy Aitken                ...!mcvax!ukc!pyrltd!jimmy
    ---mmm-----  Pyramid Technology Ltd      jimmy@pyra.co.uk
  -----mmmmm---  Pyramid House, Solartron Rd jimmy@pyramid.pyramid.com
-------mmmmmmm-  Hants GU14 7PL, ENGLAND     (+44) 252 373035