Created
October 6, 2017 21:40
-
-
Save treyharris/d914c6e3a3b0b0049d171daef1fc9c31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*-shell-script-*- | |
# Prompt user for info but don't accept the empty string | |
# | |
# TODO 2015-02-12: generalize; make a version that will | |
# accept empty, will loop until it gets non-empty, etc. | |
function promptNonNull () { | |
# args: | |
# prompt (string) User prompt. Append a trailing space if desired. | |
# variable (varname) Name of variable in which to store response. | |
local answer="${(P)2}" | |
vared -p "$1" -c answer | |
if [[ -n "${answer}" ]]; then | |
typeset -g "${2}"="${answer}" | |
else | |
echoerr "$0: null response setting $2." | |
return 1 | |
fi | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment