#!/bin/sh
# rmw-0.95.3
# ReMove to Waste folder
# Author: Andy Alt ( https://sourceforge.net/projects/rmw/ )
# October 31, 2008
# License: GPL
# Description: Linux Console trash/waste basket, bash script to move 
# files with "rm" instead of erasing them
# Use this script at your own risk.
 
WASTE=$HOME/.Waste

# PWD no longer used, see ChangeLog for details.
#PRESENTDIR=`pwd -P`
#APPENDSTR=_`date +%F_h%Im%Ms%S%p`
#APPENDSTR=_`date +%F_%Ih%Mm%Ss`

# %y = last two digits of year, %j = day of year, %I%M%S= HHMMSS 
# date --help for more details
PREPENDSTR=`date +%y%j%I%M%S`

mvargs=$1
shift

	for FILE in "$@" ; do

# -h tests whether or not the file is a symlink. If it is, it will be
# skipped. See ChangeLog for more details.
		if [ ! -h "$FILE" ]; then

# readlink finds the absolute path of the file being reMoved.
		ABSFILEPATH=`readlink -f "$FILE"`
		

		DEST=$WASTE$(dirname "$ABSFILEPATH")
		BNAME=`basename "$ABSFILEPATH"`

		if [ ! -d $DEST ]; then
			mkdir -vp "$DEST"
		fi

	      	mv $mvargs "$ABSFILEPATH" "$DEST"/"$PREPENDSTR"_"$BNAME"

else
echo Skipping Symlink \(not yet supported\)
fi


	done

exit 0

# end script
