mirror of
https://github.com/notwa/rc
synced 2024-11-05 07:19:02 -08:00
25 lines
619 B
Bash
Executable file
25 lines
619 B
Bash
Executable file
#!/usr/bin/env bash
|
|
# YES_ZSH
|
|
# YES_BASH
|
|
# NO_DASH
|
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
|
confirm() {
|
|
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
|
read -q '?Continue? [y/N] '
|
|
ret=$?
|
|
echo
|
|
return $ret
|
|
}
|
|
else
|
|
confirm() {
|
|
# specify stdin (1) to avoid taking input from pipes
|
|
[ $# -le 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
|
read -n1 -u 1 -p "Continue? [y/N] " c
|
|
echo
|
|
[ "$c" != 'y' ] && [ "$c" != 'Y' ] && return 1
|
|
return 0
|
|
}
|
|
fi
|
|
|
|
[ "${SOURCING:-0}" -gt 0 ] || confirm "$@"
|