#!/bin/sh # # "rt" K. J. Turner 27/01/97 # # This script retrieves the files/directories, given as arguments, from the # NeXT trash folder: # # rt file1 directory1/ file2 directory2 # # If a file or directory already exists in the current directory, ask before # overwriting it. prog="`basename $0`" # set program name trdir="${TRASH:-$HOME/.trash}" # set trash directory verbose="" # report retrieving trap 'echo; echo $prog: abandoned; echo; exit 1' 2 3 15 if [ $# -eq 0 ] # no parameters? then # print usage echo "usage: $prog [-l] [-v] file [file...]" exit 1 fi while [ $# -gt 0 ] do case $1 in -l) ls -l $trdir exit 0;; -v) verbose="-v";; # verbose report -*) echo "$prog: Unknown flag \"$1\"";; *) break 2;; esac shift done for file in $* # loop till all read do nodir=`expr "$file" : '\(.*\)/$'` # remove trailing slash? if [ "$nodir" != "" ] # trailing slash present? then file=$nodir # omit it fi filename="`basename \"$file\"`" # omit directory portion if [ -r $trdir/$filename ] # trash file can be read? then # check if current file exists if [ -f $file ] # current file exists? then # ask to overwrite echo -n "$prog: remove $filename (y/n)? " read ans # read Y or y if [ "$ans" != "Y" -a "$ans" != "y" ] then continue # don't retrieve if not Y or y fi fi mv $verbose $trdir/$filename $file # retrieve it else # cannot read trash file echo "$prog: cannot retrieve $filename" fi done exit 0