util for bash scripts

This commit is contained in:
2024-05-31 15:27:10 -06:00
parent f544c92c06
commit e5a32ee865

15
util.sh Normal file
View File

@@ -0,0 +1,15 @@
# prompt_char "prompt" <?timeout_sec>
# Set REPLY to the next char the user types:
prompt_char () {
exec < /dev/tty
if [ ! -z "$2" ]; then
read -t $2 -p "${1} " -n 1 -r
else
read -p "${1} " -n 1 -r
fi
if [ $? -ne 0 ]; then
REPLY=n
fi
echo # (optional) move to a new line
exec <&-
}