[comp.sources.misc] ils - enhanced ls

robertd@ncoast.UUCP (Rob DeMarco) (09/15/87)

I wrote this as an enhanced feature of ls useful in an interactive shell. It is
basically useless in a shell script - though, of course, it will work.

Program follows:
# ILS - SHELL VERSION 1.0
# WRITEN BY ROB DEMARCO (ncoast!robertd)#
# Usage:
#    ils
#    ils file/dir1 file/dir2....
#    ils -contents dir1 dir2.. +contents
#    ils -pager n
#    ils -80
#    ils -exec file1 file2... +exec
#    ils -silent
#


# Take care of line flags

export PATH || (echo "OOPS! This is not shell. Desperation time. I will feed my self to sh." ; sh $0 ; kill $$)
perm=0 ; pager=0 ; width=40 ; execflag=0 ; contents=0 ; switch=0 ; line=0 ; cflag=0 ; sflag=0

if [ "$1" = "" ] ; then
   head="`ls | head -1`"
   shead="`echo \"$head\" | cut -c1`"
   if [ "$shead" = "-" ] ; then
      set -- *
      shift
   else
      set *
   fi
   if [ "$1" = "" ] ; then
      exit 3
   fi
fi
while [ "`echo \"$1\"|cut -c1`" = "-" ];do
      if [ "$1" = "-pager" ] ; then
         shift
         pager=$1
         starter="$starter -pager $1"
         shift
         continue
      fi

      if [ "$1" = "-silent" ] ; then
         sflag=1
         starter="$starter -silent"
         shift
         continue
      fi
      if [ "$1" = "-80" ] ; then
         width=80
         starter="$starter -80"
         shift
         continue
      fi

      if [ "$1" = -contents ] ; then
         contents=1
         shift
         continue
      fi

      if [ "$1" = -exec ] ; then
         execflag=1
         shift
         continue
      fi
      break
done


for file_dir in $@ ; do
    if [ "$file_dir" = -exec ] ; then
       execflag=1
       shift
       continue
    fi
    if [ "$file_dir" = -contents ] ; then
       contents=1
       shift
       continue
    fi
    if [ "$file_dir" = +exec ] ; then
       execflag=0
       shift
       continue
    fi
    if [ "$file_dir" = +contents ] ; then
       contents=0
       shift
       continue
    fi
    if [ $execflag = 0 ] ; then
    if [ -f "$file_dir" ] ; then
       echo "`wc $file_dir`\c"
    elif [ -d $file_dir -a $contents = 0 ] ; then
       echo "\t   <DIR>\t\b\b$file_dir\c"
    elif [ -d $file_dir ] ; then
       ils $starter $file_dir/*
    else
       echo "ils:$file_dir not found." 1>&2 
       exit 4
    fi
    if [ $width = 80 -a $switch = 1 -o $width = 40 ] ; then
       echo "\n\c" ; switch=0
    elif [ $width = 80 ] ; then
       switch=1 ; echo "\t\c"
    fi
    if [ $pager -gt 0 ] ; then
       line=`expr $line + 1`
       if [ $line = `expr $pager - 1` ] ; then
          echo "*** Hit <RETURN> ***\c"
          read junk
          line=0
       fi
    fi
    else
    if [ -f $file_dir ] ; then
       $file_dir ; status=$?
    elif [ -d $file_dir -a $contents = 1 ] ; then
       ils $starter -exec $file_dir/*
    elif [ -d $file_dir ] ; then
       cd $file_dir ; cflag=1
    else
       echo "ils:$file_dir not found." 1>&2
       exit 5
    fi
    if [ "$cflag" = 0 -o $sflag = 0 ] ; then
       echo "\t\t$status\t$file_dir"
    else
       cflag=0
    fi
    fi
done

if [ $width = 80 -a $switch = 0 ] ; then
   echo "\n"
fi
--

		[> Rd
-- 
North Coast Computer Resources(ncoast) - 216-781-6201 (or 781-6202)

UUCP:decvax!cwruecmp!ncoast!robertd

Sysop: NEODG (login "sbbs")