home *** CD-ROM | disk | FTP | other *** search
- From: jerryp@cmx.npac.syr.EDU (Jerry Peek)
- Newsgroups: comp.sources.misc
- Subject: v02i091: cls, etc.: Compressed "ls"-type listing programs for BSD
- Message-ID: <8804101844.AA22110@cmx.npac.syr.EDU>
- Date: 10 Apr 88 18:44:53 GMT
- Approved: allbery@ncoast.UUCP
-
- comp.sources.misc: Volume 2, Issue 91
- Submitted-By: "Jerry Peek" <jerryp@cmx.npac.syr.EDU>
- Archive-Name: cls
-
- The standard 4.2/4.3 BSD "ls" command automatically adjusts the number
- of columns it displays to fit the longest filename in the directory.
- So, a directory listing of, say, 100 files, can scroll off the screen
- if a couple of the filenames are very long. The compressed ls programs
- limit filename length; if a name is too long, they put a ">" character
- at the end of the filename.
-
- There's more info in the README file.
-
- --Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY
- jerryp@amax.npac.syr.edu
- (315)423-1722
-
- --------------------------- Cut here and feed to sh --------------------------
- # This is a shell archive. Remove anything before this line,
- # then unpack it by saving it in a file and typing "sh file".
- #
- # Wrapped by buckwheat!jerryp on Sun Apr 10 14:27:24 EDT 1988
- # Contents: Makefile README cls cls.sed
-
- echo extracting - Makefile
- sed 's/^X//' > "Makefile" <<'X//E*O*F Makefile//'
- X#
- X# makefile for cls, clf, cls2, clf2
- X#
- X# Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY
- X# jerryp@amax.npac.syr.edu
- X# (315)423-1722
- X#
- X
- X# REMOVE ANY EXISTING LINK BECAUSE ln -s WON'T OVERWRITE EXISTING SYMLINK.
- X# THEN, TEST LINK TO BE SURE IT POINTS AT SOMETHING:
- XMAKELINK = -rm -f $@ ;\
- X ln -s $? $@ ;\
- X test -f $@
- X
- Xall: clf cls clf2 cls2
- X
- Xclf clf2 cls2: cls
- X $(MAKELINK)
- X//E*O*F Makefile//
- chmod u=rw,g=r,o=r Makefile
-
- echo extracting - README
- sed 's/^X//' > "README" <<'X//E*O*F README//'
- XThis package of files sets up four programs that do "compressed" ls-type
- Xlistings. They only work on BSD 4.2 and 4.3 UNIX (also ULTRIX); you won't
- Xneed them on SysV, XENIX, or other systems which limit filenames to 14
- Xcharacters or less.
- X
- XI wrote them because the standard "ls" command automatically adjusts the
- Xnumber of columns it displays to fit the longest filename. So, a directory
- Xlisting of, say, 100 files, can scroll off the screen if a couple of the
- Xfilenames are very long. The compressed ls programs limit filename length;
- Xif a name is too long, they put a ">" character at the end of the filename.
- XSee the program's comment block for more explanation.
- X
- XHere's an example.
- X
- X % ls
- X 1test junque3
- X 2test long_exe_file_name,_etc._etc.
- X 3test long_text_file_name,_etc._etc.
- X 4test shortexe
- X dir_short shorttext
- X directory_with_long_name_too test1
- X junque1 test2
- X junque2
- X % cls
- X 1test dir_short junque3 shorttext
- X 2test directory_wit> long_exe_file> test1
- X 3test junque1 long_text_fil> test2
- X 4test junque2 shortexe
- X % cls2
- X 1test 2test 3test 4test dir_short
- X directory_wit> junque1 junque2 junque3 long_exe_file>
- X long_text_fil> shortexe shorttext test1 test2
- X % ls -F
- X 1test junque3
- X 2test* long_exe_file_name,_etc._etc.*
- X 3test long_text_file_name,_etc._etc.
- X 4test shortexe*
- X dir_short/ shorttext
- X directory_with_long_name_too/ test1
- X junque1 test2
- X junque2
- X % clf
- X 1test dir_short/ junque3 shorttext
- X 2test* directory_wi>/ long_exe_fil>* test1
- X 3test junque1 long_text_fil> test2
- X 4test junque2 shortexe*
- X % clf2
- X 1test 2test* 3test 4test dir_short/
- X directory_wi>/ junque1 junque2 junque3 long_exe_fil>*
- X long_text_fil> shortexe* shorttext test1 test2
- X
- XThe clx2 programs run faster because they don't have to count the number
- Xof lines in the "ls" output. But, the ordering is different.
- X
- XAll four programs actually run from the same code; the real source file is
- X"cls", and the others are symbolic links to it. I use symlinks instead of
- Xhard links because I maintain the software with RCS. The short makefile
- XI've sent along should set things up for you... just type "make".
- XMove the "cls.sed" program to whatever directory you'd like to keep it, then
- Xedit the "sed=" line in the "cls" file -- to let it find the "cls.sed" file.
- X
- XThe programs are quick hacks, but they've been very very useful.
- XIf anyone makes any fixes or improvements, please send them to me!
- X
- X--Jerry Peek, Northeast Parallel Architectures Center, Syracuse, NY
- X jerryp@amax.npac.syr.edu
- X (315)423-1722
- X//E*O*F README//
- chmod u=rw,g=r,o=r README
-
- echo extracting - cls
- sed 's/^X//' > "cls" <<'X//E*O*F cls//'
- X#! /bin/sh
- X# $Header: cls,v 1.2 88/02/03 14:21:20 jerryp Exp $
- X#
- X### clf,cls,clf2,cls2 - 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## USAGE:
- X## % clf [file] [files]
- X## % clf2 [file] [files]
- X## % cls [file] [files]
- X## % cls2 [file] [files]
- X
- Xtemp=/tmp/CLS$$ # TEMP FILE
- X
- X# pr PROGRAM: MAKE 5 COLUMNS, NO HEADING, 78 COLUMNS WIDE:
- Xpr='pr -5 -t -w78'
- X
- X# sed PROGRAM... IF LINE IS OVER 14 CHARACTERS AND ENDS WITH SYMBOL
- X# "*", "/", "@", OR "=", TRUNCATE AFTER 12 AND REPLACE WITH >SYMBOL...
- X# OTHERWISE, IF NAME IS OVER 14 CHARACTERS, TRUNCATE AFTER 13; ADD A >
- Xsed='sed -f /u1/npac/jerryp/.lib/cls.sed'
- X
- Xcase "$0" in
- X*clf2) ls -F1 "$@" | $sed | $pr -l1
- X exit 0
- X ;;
- X*cls2) ls -1 "$@" | $sed | $pr -l1
- X exit 0
- X ;;
- X*clf) ls -F1 "$@" | $sed > $temp ;;
- X*cls) ls -1 "$@" | $sed > $temp ;;
- X*) echo "$0: Help! Shouldn't get here!";
- X exit 1
- X ;;
- Xesac
- X
- X# (THESE COMMANDS ONLY DONE BY cls AND clf.)
- X# LENGTH OF LISTING = ( number of files / 5 ) + 1
- X$pr -l`expr \( \`wc -l < $temp\` / 5 \) + 1` $temp
- Xrm -f $temp
- X//E*O*F cls//
- chmod u=rwx,g=rx,o=rx cls
-
- echo extracting - cls.sed
- sed 's/^X//' > "cls.sed" <<'X//E*O*F cls.sed//'
- X/[/@*=]$/s/^\(............\)...*\([/@*=][/@*=]*\)$/\1>\2/
- Xs/^\(.............\)...*/\1>/
- X//E*O*F cls.sed//
- chmod u=r,g=r,o=r cls.sed
-
- echo Inspecting for damage in transit...
- temp=/tmp/shar$$; dtemp=/tmp/.shar$$
- trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
- cat > $temp <<\!!!
- 18 70 391 Makefile
- 67 361 3182 README
- 57 348 1781 cls
- 2 2 88 cls.sed
- 144 781 5442 total
- !!!
- wc Makefile README cls cls.sed | sed 's/^X//' | diff -b $temp - >$dtemp
- if [ -s $dtemp ]
- then echo "Ouch [diff of wc output]:" ; cat $dtemp
- else echo "No problems found."
- fi
- exit 0
-