From e5cd56bfcfa8a73b3ee734108201c8ccffb6db6b Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Mon, 12 Oct 2020 07:54:06 -0400
Subject: [PATCH] Import updated utils script

---
 utils.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/utils.sh b/utils.sh
index 55c1efc..c61bce7 100755
--- a/utils.sh
+++ b/utils.sh
@@ -5,7 +5,8 @@
  # Intended to hold very common functionality (that's surprisingly not built into bash) such as string upper/lower,
  # and checking current user value, and prompts of yes/no user input.
  #
- # Version 1.0.
+ # https://git.brandon-rodriguez.com/scripts/bash/utils
+ # Version 1.1.
  ##
 
 
@@ -504,6 +505,50 @@ function to_lower () {
 
 #region Display Functions
 
+###
+ # Prompts user for yes/no confirmation. Returns True if yes.
+ # Accepts "yes", "ye", and "y". Input values are treated as case insensitive.
+ # All other values are treated as "no".
+ #
+ # Return Variable(s): return_value
+ ##
+function get_user_confirmation () {
+    # Check number of passed function args.
+    if [[ ${#} == 0 ]]
+    then
+        # Handle prompt for no args passed.
+        echo -e "[${text_cyan}Yes${text_reset}/${text_cyan}No${text_reset}]"
+
+    elif [[ ${#} == 1 ]]
+    then
+        # Handle prompt for one arg passed.
+        echo -e "${1} [${text_cyan}Yes${text_reset}/${text_cyan}No${text_reset}]"
+
+    else
+        # Handle for too many args.
+        echo -e "${text_red}Too many args passed. Expected zero or one arg, received ${#}.${text_reset}"
+        exit 1
+    fi
+
+    # Get user input.
+    read -p " " return_value
+    echo ""
+
+    # Convert input to lower for easy parsing.
+    to_lower "${return_value}"
+
+    # Finally parse user input.
+    if [[ "${return_value}" == "y" || "${return_value}" == "ye" || "${return_value}" == "yes" ]]
+    then
+        # User provided "yes". Return True.
+        return_value=true
+    else
+        # For all other values, return False.
+        return_value=false
+    fi
+}
+
+
 ###
  # Prints out all available text colors provided by this script.
  #
-- 
GitLab