ao-mud is a spellbook of well-commented atomic bash scripts that each do one thing. we are building semantic building blocks for an autonomously-evolving digital spellcasting language.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
744 B

#!/usr/bin/env sh
# Define ask_Yn, which asks a yes or no question and saves the result in the given variable name (defaults to yes)
# Takes one arg, which is the variable name where the result will be saved
# No is 0 and Yes is 1
source say
ask_Yn() {
if [ -n "$2" ]; then
say_inline "$2 (Y/n): "
fi
STTY_CONFIG=$(stty -g) # Save current stty config
stty raw -echo # Disable echo
ANSWER=$(head -c 1) # Scrape terminal input
stty $STTY_CONFIG # Restore stty config
if [ "$ANSWER" != "${ANSWER#[Nn]}" ]; then
say "N"
export "${1}=0"
else
say "Y"
export "${1}=1"
fi
}
# Check if the script is being called from another script
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
# If not, call the function
ask_Yn "$@"
fi