aboutsummaryrefslogtreecommitdiffstats
path: root/shlib/prompt.sh
blob: 6a63db04d95cb193a081b42a2f517d771fb8cd2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# shellcheck shell=sh
[ -n "${DOTFILES_PROMPT_LOADED}" ] && return
readonly DOTFILES_PROMPT_LOADED=1

# Prompt the user for confirmation on an action.
#
# Args:
#   $1: The question to prompt for. Answer choices
#      will be added onto the end.
#
# Returns:
#   0 on yes. 1 on no.
prompt_for_confirmation() {
  (
    printf "%s [y/n]: " "$1"
    read -r answer
    if [ "$answer" != "${answer#[Yy]}" ]; then
      return 0
    else
      return 1
    fi
  )
}