Skip to content

Commit fd495bb

Browse files
author
Giles Westwood
committed
add prompt helpers
1 parent 422480b commit fd495bb

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

lib/prompt.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# confirm "Would you really like to do a X?" && run_x || exit
2+
# use return rather than exit if bash function
3+
# NOTE: this will not work in a loop that is using read, use for loops instead with an altered IFS.
4+
sk-prompt-confirm() {
5+
read -r -p "${1:-Are you sure? [Y/n]} " response
6+
case $response in
7+
[yY][eE][sS]|[yY])
8+
true
9+
;;
10+
[n])
11+
false
12+
;;
13+
*)
14+
true
15+
;;
16+
esac
17+
}
18+
19+
sk-prompt-confirm-timeout() {
20+
read -r -t 5 -p "${1:-Are you sure? [Y/n]} " response || return 1
21+
case $response in
22+
[yY][eE][sS]|[yY])
23+
true
24+
;;
25+
[n])
26+
false
27+
;;
28+
*)
29+
true
30+
;;
31+
esac
32+
}
33+
34+
35+

0 commit comments

Comments
 (0)