#!/bin/bash
#

temporal=$(mktemp)

function busqueda () 
{
retval=$(Xdialog --title  "Seleccione el directorio de bsqueda" --dselect ~ 0 0 2>&1)
if [ "$?" -eq "0" ]; then
	retval1=$(Xdialog --title  "Buscador" --inputbox "Introduzca la cadena de bsqueda (puede utilizar *)" 0 0 2>&1)
	if [ "$?" -eq "0" ]; then
		find "$retval" -iname "$retval1" > $temporal 2> /dev/null | Xdialog --title  "Buscador" --no-buttons --infobox "Buscando... Por favor, espere" 0 0 5000
		if [ ! -z "$(cat $temporal)" ]; then
			fichero=`Xdialog --title "Buscador" --menubox "Seleccione un fichero de la lista" 500x300 20 $(cat $temporal | tr -s " " "" | sed -e 's,^/\(.*\)$,"/\1" \.,') 2>&1`
			[ "$?" -eq "0" ] && rox-filer "$(dirname "`echo $fichero | tr -s "" " " | sed -e 's/^"\(.*\)/\1/'`")"
		else
			Xdialog --title "Buscador" --yesno "No se encontr ninguna coincidencia\n\nQuiere realizar una nueva bsqueda?" 0 0
			[ "$?" -eq "0" ] && busqueda
		fi
	fi
fi
}

busqueda

rm -f $temporal
