#! /bin/sh # # File: vpurge.sh # Abstract: Remove old file versions created by emacs. # Usage: See -h for help. # Author: Bill.Costa@unh.edu # #============================================================================== help () { cat <&2 shift 2 while [ $# -gt 0 ] do echo "_ $1" >&2 shift done if [ $1 -gt 0 ] then exit $1 else echo "_ internal logic error, forcing error exit" exit 9 fi; } #============================================================================== # MAIN LINE ================================================================= #============================================================================== verbose=off interactive=off test=off force=off #-------------------------------+ # Process command line options | # first. | #-------------------------------+ while [ $# -gt 0 ] do case "$1" in -h) help; exit 0;; -i) verbose=off; interactive=on; test=off; force=off;; -v) verbose=on; interactive=off; test=off; force=off;; -t) verbose=off; interactive=off; test=on; force=off;; -f) verbose=off; interactive=off; test=off; force=on;; --) shift; break;; -*) echo >&2 "invalid option '$1'; try -h for help" exit 1;; *) break;; esac shift done #-------------------------------+ # "$@" now contains all file | # names. If there are none, | # then generate our own. If | # there are still none, exit. | #-------------------------------+ if [ $# -gt 0 ] then allFiles="$@" else allFiles="`(ls -1 | grep -v '~$') 2>/dev/null`" fi; [ "$allFiles" = "" ] && exit; #-------------------------------+ # Prescan our args for any | # problems. | #-------------------------------+ for nxtFile in $allFiles do case "$nxtFile" in *~) die 1 "invalid file specified: $nxtFile" "try -h for help";; esac done #-------------------------------+ # Now do the deed. | #-------------------------------+ for next in $allFiles do hit="`ls $next~ 2>/dev/null`" hit="$hit `(ls $next.~*~ 2>/dev/null | egrep '\.~[0-9]+~$')`" if [ "$hit" = " " ] then : elif [ "$test" = "on" ] then ls $hit elif [ "$interactive" = "on" ] then rm -i $hit elif [ "$verbose" = "on" ] then rm -e $hit elif [ "$force" = "on" ] then rm -f $hit else rm $hit fi done #==[ EOF: vpurge.sh ]==========================================================