yn() {
  printf '%s [y/N]: ' "$1"
  [ -t 0 ] && stty -echo -icanon
  answer=$(dd ibs=1 count=1 2>/dev/null)
  [ -t 0 ] && stty echo icanon
  printf '%s\n' "${answer}"
  glob "${answer}" '[yY]'
}

glob() {
  # this is a simple wrapper around a case statement to allow
  # for simple string comparisons against globs.
  # example: if glob "Hello World" '* World'; then
  # disable this warning as it is the intended behavior.
  # shellcheck disable=SC2249,SC2254
  case $1 in "$2") return 0 ;; esac
  return 1
}

# if yn "generate a password?"; then

confirm_ask() {
  print '%s' "$1 [y/n]? "
  read -r reply
  case ${reply} in
    Y*|y*) true ;;
    *) false ;;
  esac
}
