diff --git a/trm.sh b/trm.sh index aaa8ae2..5e6c56e 100755 --- a/trm.sh +++ b/trm.sh @@ -16,7 +16,7 @@ # Parse command line args OPERATOR="mv" # Can be overriden with -c option - OPTLIST='ctdv' # List of all legal options + OPTLIST='cdtsv' # List of all legal command line options OPTIND=1 # getopts may have been previously used in this context TESTMODE="" VERBOSE="" @@ -36,6 +36,11 @@ rm -rf ${VERBOSE} ${GRAVEYARD}/* ${GRAVEYARD}/.[-z]* ;; + # Expand symlinks + s) + SYMEXPAND="symexpand" + ;; + # Don't do anything, just show what you would do t) TESTMODE="testmode" @@ -58,7 +63,27 @@ shift $((OPTIND-1)) for arg in $* do - REALPATH=$(readlink -f $arg) + + # Only expand symlinks if we ask for it + + if [ -L $arg ] + then + + # Expand the symlink + if [ -n "${SYMEXPAND}" ] + then + REALPATH=$(readlink $arg) + + # Treat the symlink as a normal file + else + REALPATH=$(readlink -f $(dirname $arg))/$arg + fi + + # Process normal files and directories + else + REALPATH=$(readlink -f $arg) + fi + SRCDIR=$(dirname $REALPATH) SRCFIL=$(basename $REALPATH) DESDIR=${GRAVEYARD}${SRCDIR}