home *** CD-ROM | disk | FTP | other *** search
/ The UNIX CD Bookshelf / OREILLY_TUCB_UNIX_CD.iso / upt / examples / SUN4C / ARCHIVE / DIRTOP.Z / DIRTOP / sbin / dirtop
Encoding:
Text File  |  1993-01-01  |  1.1 KB  |  39 lines

  1. #! /bin/sh
  2. ###    dirtop - put 'ls' listing in non-scrolling area at top of VTxxx screen.
  3. ###    Usage: dirtop [-c]
  4. # Only for VTxxx terminals and compatibles, sigh.
  5.  
  6. ls="/bin/ls -FC"         # ls command to use
  7. maxlines=10              # if more lines in listing than this, quit
  8.  
  9. # UNCOMMENT THE LINE FOR YOUR SYSTEM:
  10. #cmd=echo   c='\c'   e='\033'   n=            # SysV
  11. cmd=/usr/5bin/echo   c='\c'   e='\033'   n=        # SunOS
  12. #cmd=/bin/echo   c=   e="`echo e | tr e '\033'`"   n=-n    # BSD
  13.  
  14. case "$1" in
  15. -c) $cmd $n "${e}[r${e}[2J${c}"; exit 0;;    # just reset screen
  16. "") ;;
  17. *) echo "Usage: `basename $0` [-c]" 1>&2; exit 1 ;;
  18. esac
  19.  
  20. temp=/tmp/DIRTOP$$
  21. trap 'rm -f $temp; exit' 0 1 2 15
  22.  
  23. $ls > $temp
  24. # set number of lines to clear: one more than length of ls listing:
  25. lines=`expr 1 + \`wc -l < $temp\``
  26. if [ $lines -gt $maxlines ]
  27. then
  28.     echo "`basename $0`: Directory listing > $maxlines lines" 1>&2
  29.     exit 1
  30. else
  31.     # CLEAR SCREEN.  SET NO-SCROLL AREA:
  32.     $cmd $n "${e}[2J${c}"
  33.     $cmd $n "${e}[${lines};24r${c}"
  34.     # MOVE CURSOR TO TOP-LEFT CORNER, THEN PRINT LISTING:
  35.     $cmd $n "${e}[0;0f${c}"
  36.     cat $temp
  37.     exit
  38. fi
  39.