#! /bin/bash
# pu - purge obsolete files
# usage pu [option]
# option specifies in a compact form common extensions for files
# to be purged, accordin to the following list
#   default:  *.bak, *.~* *.backup
#   latex     latex auxialiary files, i.e. aux log lof lot toc ind ilg idx blg bbl

# EXT is an array containing extensions of files to be purged
declare -a EXT


case $1 in
    "")
       echo "purge obsolete files (*.bak, *.~*)"
       rm -f *~
       EXT=("bak" "*~" "backup")
    ;;
    "latex")
       echo "purge latex auxiliary files"
       echo "files .dvi and .ps will be NOT removed!"
       EXT=(aux log lof lot toc ind ilg idx blg bbl out inx)
    ;;
    "--help")
       echo purge obsolete files from current directory
       echo usage $0 "[family]"
       echo family specifies in a compact way some common extensions
       echo "according to the following ones"
       echo "   default (nothing)    *.bak *.~*"
       echo "   latex                latex auxiliary files"
       echo "   "
    ;;
esac

# purge files having extension specified by the array $EXT
for I in ${EXT[*]} ; do
  #echo *.$I
  #ls *.$I
  rm -f *.${I}
done
ls
