1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-18 17:53:23 -07:00
rc/sh/confirm
2021-07-29 00:37:35 -07:00

24 lines
602 B
Bash
Executable File

#!/usr/bin/env bash
# YES_ZSH
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 "$@"