# The prompt function takes a string that will be displayed as the
# prompt as its first parameter and an optional second parameter of
# either 'Y' or 'N' which represents the default choice should nothing
# be entered.
#
# If no default is provided then 'Y' will be used.

function prompt {
	echo
    if [[ -z $2 || ${2^} = Y* ]]; then
        prompt='Y/n'
        default='Y'
    elif [[ ${2^} = N* ]]; then
        prompt='y/N'
        default='N'
    fi
    
	while true; do
		read -p "$1 [$prompt] " ans
		
		if [[ -z $ans ]]; then
			ans=$default
        fi
        
		if [[ ${ans^} = Y* ]]; then
			echo
			return 0
		elif [[ ${ans^} = N* ]]; then
			echo
			return 1
		fi
	done
}
