added conditional prompt function

This commit is contained in:
Lucas Frérot 2024-12-31 13:34:53 +01:00
parent 2e6f71842f
commit 2781ddf6a3
No known key found for this signature in database
GPG Key ID: 03B54A50E3FBA7E8
1 changed files with 14 additions and 1 deletions

15
rtenets
View File

@ -77,10 +77,23 @@ alt_var() {
if is_set "${variable}"; then if is_set "${variable}"; then
printf "%s" "$(eval "printf \"%s\" \"\${${variable}}\"")" printf "%s" "$(eval "printf \"%s\" \"\${${variable}}\"")"
else else
printf "%s" "$value_if_unset" printf "%s" "${value_if_unset}"
fi fi
} }
# Enter value if unset
cond_enter() {
local input="$1"
local var_name="$2"
local value="$(alt_var "" "${var_name}")"
if [[ "${value}" == "" ]]; then
value="$(enter "${input}")"
fi
printf "%s" "${value}"
}
# Check that command exists # Check that command exists
has_command() { has_command() {
command -v "$1" >/dev/null 2>&1 command -v "$1" >/dev/null 2>&1