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

destination=$(zenity --file-selection --directory --title "Where to move files?")

for file in $NAUTILUS_SCRIPT_SELECTED_URIS; do \

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

	if [[ -w $destination && -e $destination/$short_file_name ]]; then \
		confirm=$(zenity --question --text "Overwrite File $destination/$short_file_name?"; echo $?)
		if [[ $confirm == 0 ]]; then
			mv "$file_name" $destination
			if (( $? != 0 )); then
			zenity --info --text "Something went wrong" --title "Failure"
			fi
		fi
	elif [[ -w $destination && ! -e $destination/$short_file_name ]]; then \
		mv "$file_name" $destination
		if (( $? != 0 )); then
		zenity --info --text "Something went wrong" --title "Failure"
		fi
	elif [[ ! -w $destination && -e $destination ]]; then
		which gksu
		if (( $? == 0 )); then
			gksu -u root "mv \"$file_name\" $destination"
		else	zenity --info --title "Warning" --text "gksu is not installed or not in $PATH"
	else	zenity --info --title "Failure" --text "$destination does either not\nexist or is not writable"
	fi; \
done
