cdg asks if multiple solutions are possible

This commit is contained in:
Thomas Forgione 2017-11-09 09:55:18 +01:00
parent 1131871d77
commit ed3162d200
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
1 changed files with 20 additions and 5 deletions

View File

@ -90,16 +90,31 @@ if [ -d "$GCLONE_PATH" ]; then
echo "This function expects a single parameter"
return 1
else
dir=`find $GCLONE_PATH -maxdepth 3 -name $1`
found_dirs=`find $GCLONE_PATH -maxdepth 3 -name $1 | sort`
total=`echo $found_dirs | wc -l`
if [[ "" == "$dir" ]]; then
if [[ "" == "$found_dirs" ]]; then
echo "$1 not found"
return 2
elif [ `echo $dir | wc -l` -gt 1 ]; then
echo "Multiple entries for $1 found"
elif [ $total -gt 1 ]; then
counter=0
echo "Multiple entries for $1 found:"
echo $found_dirs | while read found_dir; do
counter=$(($counter+1))
echo "["$counter"]" $found_dir
done
read choice
if [[ "$choice" == "" ]]; then
cd `echo $found_dirs | head -1 | tail -1`
elif [[ "$choice" =~ '^[0-9]+$' ]] && [ $choice -le $total ] && [ $choice -gt 0 ]; then
cd `echo $found_dirs | head -$choice | tail -1`
else
echo "I expected a number that was less than the max..."
return 3
fi
return 3
else
cd $dir
cd $found_dirs
fi
fi
}