These are the scripts I use to trash and "untrash" (remove from trash) files.
I set the $TRASH environment variable to $HOME/trash. I do not like the freedesktop convention on using .local/share
trash:
Code:
#!/bin/sh
# trash: move files to trash $TRASH
# this file in public domain
# get directory of deleted files
filesdir="$(dirname "$filename")"
if [ "$(basename $filesdir)" != "files" ]
then
echo "trash: $basename: file is not in trash" >&2
exit 1
fi
# get file containing information on deleted file
infofile="$(getinfo "$filesdir" "$basename")"
if [ ! -f "$infofile" ]
then
echo "trash: $basename: cannot find original directory" >&2
exit 1
fi
# get original name of deleted file
origfile="$(getorigfile "$infofile" "$basename")"
if [ -e "$origfile" ]
then
echo "trash: $basename: file already exists on original directory" >&2
exit 1
fi
# move deleted file to its original place
if ! mv "$filename" "$origfile"
then
echo "trash: $basename: cannot move file to its original directory" >&2
exit 1
fi
# remove deleted file's information file
if ! rm "$infofile"
then
echo "trash: $basename: cannot clean file from trash" >&2
exit 1
fi
done