#!/bin/bash

if [[ -a /dev/urandom ]]; then
	randomizer=/dev/urandom;
elif [[ -a /dev/random ]]; then
	randomizer=/dev/random;
fi

echo $NAUTILUS_SCRIPT_SELECTED_URIS > ~/.gnome2/temp_shred_list

for file in $(cat ~/.gnome2/temp_shred_list); do

shortfile=$(echo $file | sed -e 's/\%20/\ /g' -e 's/.*\///g')

file_name=$(echo $file | sed -e 's/file:\/\///g' -e 's/\%20/\ /g')

zenity --question --title "Shredder" --text "Really shred $shortfile?"

if (( "$?" == 1 )) ; then
	exit
else
	if [[ $randomizer == "" ]]; then
		shred -u -z -n 50 "$file_name"
		if (( $? == 0 )); then
			zenity --info --text="$shortfile has been shred" --title "Success"
		else	zenity --info --text="$shortfile couldn't be shred" --title "Failure"
		fi
	else	shred -u -z -n 50 --random-source=$randomizer "$file_name"
		if (( $? == 0 )); then
			zenity --info --text="$shortfile has been shred" --title "Success"
		else	zenity --info --text="$shortfile couldn't be shred" --title "Failure"
		fi
	fi
fi;

done

rm -f ~/.gnome2/temp_shred_list
