home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8709 / 7 < prev    next >
Encoding:
Text File  |  1987-09-16  |  3.6 KB  |  164 lines

  1. Article 8 of comp.sources.misc:
  2. Path: tut!osu-cis!cbosgd!ucbvax!husc6!necntc!ncoast!allbery
  3. From: robertd@ncoast.UUCP (Rob DeMarco)
  4. Newsgroups: comp.sources.misc
  5. Subject: ils - enhanced ls
  6. Message-ID: <4524@ncoast.UUCP>
  7. Date: 15 Sep 87 01:13:09 GMT
  8. Sender: allbery@ncoast.UUCP
  9. Organization: Cleveland Public Access UN*X, Cleveland, Oh
  10. Lines: 148
  11. Approved: allbery@ncoast.UUCP
  12. X-Archive: comp.sources.misc/8709/7
  13.  
  14. I wrote this as an enhanced feature of ls useful in an interactive shell. It is
  15. basically useless in a shell script - though, of course, it will work.
  16.  
  17. Program follows:
  18. # ILS - SHELL VERSION 1.0
  19. # WRITEN BY ROB DEMARCO (ncoast!robertd)#
  20. # Usage:
  21. #    ils
  22. #    ils file/dir1 file/dir2....
  23. #    ils -contents dir1 dir2.. +contents
  24. #    ils -pager n
  25. #    ils -80
  26. #    ils -exec file1 file2... +exec
  27. #    ils -silent
  28. #
  29.  
  30.  
  31. # Take care of line flags
  32.  
  33. export PATH || (echo "OOPS! This is not shell. Desperation time. I will feed my self to sh." ; sh $0 ; kill $$)
  34. perm=0 ; pager=0 ; width=40 ; execflag=0 ; contents=0 ; switch=0 ; line=0 ; cflag=0 ; sflag=0
  35.  
  36. if [ "$1" = "" ] ; then
  37.    head="`ls | head -1`"
  38.    shead="`echo \"$head\" | cut -c1`"
  39.    if [ "$shead" = "-" ] ; then
  40.       set -- *
  41.       shift
  42.    else
  43.       set *
  44.    fi
  45.    if [ "$1" = "" ] ; then
  46.       exit 3
  47.    fi
  48. fi
  49. while [ "`echo \"$1\"|cut -c1`" = "-" ];do
  50.       if [ "$1" = "-pager" ] ; then
  51.          shift
  52.          pager=$1
  53.          starter="$starter -pager $1"
  54.          shift
  55.          continue
  56.       fi
  57.  
  58.       if [ "$1" = "-silent" ] ; then
  59.          sflag=1
  60.          starter="$starter -silent"
  61.          shift
  62.          continue
  63.       fi
  64.       if [ "$1" = "-80" ] ; then
  65.          width=80
  66.          starter="$starter -80"
  67.          shift
  68.          continue
  69.       fi
  70.  
  71.       if [ "$1" = -contents ] ; then
  72.          contents=1
  73.          shift
  74.          continue
  75.       fi
  76.  
  77.       if [ "$1" = -exec ] ; then
  78.          execflag=1
  79.          shift
  80.          continue
  81.       fi
  82.       break
  83. done
  84.  
  85.  
  86. for file_dir in $@ ; do
  87.     if [ "$file_dir" = -exec ] ; then
  88.        execflag=1
  89.        shift
  90.        continue
  91.     fi
  92.     if [ "$file_dir" = -contents ] ; then
  93.        contents=1
  94.        shift
  95.        continue
  96.     fi
  97.     if [ "$file_dir" = +exec ] ; then
  98.        execflag=0
  99.        shift
  100.        continue
  101.     fi
  102.     if [ "$file_dir" = +contents ] ; then
  103.        contents=0
  104.        shift
  105.        continue
  106.     fi
  107.     if [ $execflag = 0 ] ; then
  108.     if [ -f "$file_dir" ] ; then
  109.        echo "`wc $file_dir`\c"
  110.     elif [ -d $file_dir -a $contents = 0 ] ; then
  111.        echo "\t   <DIR>\t\b\b$file_dir\c"
  112.     elif [ -d $file_dir ] ; then
  113.        ils $starter $file_dir/*
  114.     else
  115.        echo "ils:$file_dir not found." 1>&2 
  116.        exit 4
  117.     fi
  118.     if [ $width = 80 -a $switch = 1 -o $width = 40 ] ; then
  119.        echo "\n\c" ; switch=0
  120.     elif [ $width = 80 ] ; then
  121.        switch=1 ; echo "\t\c"
  122.     fi
  123.     if [ $pager -gt 0 ] ; then
  124.        line=`expr $line + 1`
  125.        if [ $line = `expr $pager - 1` ] ; then
  126.           echo "*** Hit <RETURN> ***\c"
  127.           read junk
  128.           line=0
  129.        fi
  130.     fi
  131.     else
  132.     if [ -f $file_dir ] ; then
  133.        $file_dir ; status=$?
  134.     elif [ -d $file_dir -a $contents = 1 ] ; then
  135.        ils $starter -exec $file_dir/*
  136.     elif [ -d $file_dir ] ; then
  137.        cd $file_dir ; cflag=1
  138.     else
  139.        echo "ils:$file_dir not found." 1>&2
  140.        exit 5
  141.     fi
  142.     if [ "$cflag" = 0 -o $sflag = 0 ] ; then
  143.        echo "\t\t$status\t$file_dir"
  144.     else
  145.        cflag=0
  146.     fi
  147.     fi
  148. done
  149.  
  150. if [ $width = 80 -a $switch = 0 ] ; then
  151.    echo "\n"
  152. fi
  153. --
  154.  
  155.         [> Rd
  156. -- 
  157. North Coast Computer Resources(ncoast) - 216-781-6201 (or 781-6202)
  158.  
  159. UUCP:decvax!cwruecmp!ncoast!robertd
  160.  
  161. Sysop: NEODG (login "sbbs")
  162.  
  163.  
  164.