-
Notifications
You must be signed in to change notification settings - Fork 1
/
confirm.sh
67 lines (61 loc) · 1.14 KB
/
confirm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
function ih::ask::confirm() {
local action="${1}"
local response
echo "${action}"
if [[ $SKIP_CONFIRMATION -eq 1 ]]; then
return 0
fi
echo "OK to proceed? (y/N)"
read -rsn1 response
case "${response}" in
[yY])
return 0
;;
*)
return 1
;;
esac
}
# Prints the content of $1 and then asks the
# user to choose yes, no, or retry.
# If the user chooses yes, returns 0
# If the user chooses retry, returns 1
# If the user chooses no, returns 2
function ih::ask::yes-no-retry() {
local action="${1}"
local response
echo "${action}"
echo "Yes/No/Retry (y/n/r)"
read -rsn1 response
case "${response}" in
[yY])
return 0
;;
[rR])
return 1
;;
*)
return 2
;;
esac
}
# Prints the content of $1 and then asks the
# user to choose retry or cancel.
# If the user chooses cancel, returns 1
# Otherwise, returns 0
function ih::ask::retry-cancel() {
local action="${1}"
local response
echo "${action}"
echo "Retry/Cancel (R/c)"
read -rsn1 response
case "${response}" in
[cC])
return 1
;;
*)
return 0
;;
esac
}