home *** CD-ROM | disk | FTP | other *** search
/ The UNIX CD Bookshelf / OREILLY_TUCB_UNIX_CD.iso / upt / examples / LINUX / ARCHIVE / CLS.Z / CLS / sbin / clf2 < prev    next >
Encoding:
Text File  |  1992-12-11  |  1.3 KB  |  41 lines

  1. #! /bin/sh
  2. ### clf,cls,clf2,cls2 - compressed "ls" and "ls -F" directory listings
  3. ### Usage: cmd [dirs]
  4.  
  5. # To install the program, put it in an executable file named \fIcls\fP.
  6. # Then make three links to it:
  7. #
  8. # % chmod 755 cls
  9. # % ln cls clf
  10. # % ln cls cls2
  11. # % ln cls clf2
  12.  
  13. # UNCOMMENT THE RIGHT ONE FOR YOUR SYSTEM:
  14. ls='/bin/ls -1'     # BSD
  15. #ls='/bin/ls'       # Sys V
  16.  
  17. temp=/tmp/CLS$$     # TEMP FILE
  18. umask 077           # MAKE TEMP FILE PRIVATE
  19.  
  20. # pr PROGRAM: MAKE 5 COLUMNS, NO HEADING, 78 COLUMNS WIDE:
  21. pr='pr -5 -t -w78'
  22.  
  23. # sed SCRIPT:  IF LINE IS OVER 14 CHARACTERS AND ENDS WITH SYMBOL
  24. # "*", "/", "@", OR "=", TRUNCATE AFTER 12 AND REPLACE WITH >SYMBOL...
  25. # OTHERWISE, IF NAME IS OVER 14 CHARACTERS, TRUNCATE AFTER 13; ADD A >
  26. sed='/[/@*=]$/s/^\(............\)...*\([/@*=][/@*=]*\)$/\1>\2/
  27. s/^\(.............\)...*/\1>/'
  28.  
  29. case "$0" in
  30. *clf2)  $ls -F ${1+"$@"} | sed -e "$sed" | $pr -l1; exit ;;
  31. *cls2)  $ls ${1+"$@"} | sed -e "$sed" | $pr -l1; exit ;;
  32. *clf)   $ls -F ${1+"$@"} | sed -e "$sed" > $temp ;;
  33. *cls)   $ls ${1+"$@"} | sed -e "$sed" > $temp ;;
  34. *)  echo "$0: Help!  Shouldn't get here!"; exit 1 ;;
  35. esac
  36.  
  37. # (THESE COMMANDS ONLY DONE BY cls AND clf.)
  38. # LENGTH OF LISTING = ( number of files / 5 ) + 1
  39. $pr -l`expr \( \`wc -l < $temp\` / 5 \) + 1` $temp
  40. rm -f $temp
  41.