Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds functions to prompt the user #7

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,31 @@ function newenv {
fi
success "Virtualenv ${envname} created"
}

# Inserts a pause in the progress, and an option to terminate early.
#
# Usage: should_continue
function should_continue {
if read -q "?Paused. Hit 'y' when ready to continue, or 'n' to terminate "; then
echo -e "\nOk, continuing...\n"
else
echo -e "\nAborting\n"
exit 1
fi
}

# Asks an optional question and returns a non-zero value if the user
# responds anything other than `y`.
#
# Should be used in an `if` statement:
#
# if ask "About to remove resource, continue?"; then
# ... do the deed
# fi
# Usage: ask [PROMPT]
function ask {
read -q "?${1:-Proceed?} [y/n] "
res=$?
echo -n "\n"
return $res
}