#!/bin/bash
#########################################################
#							#
# This are NScripts v3.4				#
#							#
# Licensed under the GNU GENERAL PUBLIC LICENSE 3	#
#							#
# Copyright 2007 - 2008 Christopher Bratusek		#
#							#
#########################################################

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

echo $NAUTILUS_SCRIPT_SELECTED_URIS > ~/.gnome2/temp_shred_list

zenity --question --title "Shredder" --text "Really want to shred the selected file(s)?\nShredding means _completely_ removing them and differs from deleting!"

if (( $? == 0 )); then
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')

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

done
fi

rm -f ~/.gnome2/temp_shred_list

