From 67b5000f046d5bd1683c8c8a5ac2e01d7fefa726 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Fri, 15 Mar 2024 16:03:31 +0100
Subject: [PATCH] handle empty selection in showSelectAndInput

---
 localdump.sh | 49 ++++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/localdump.sh b/localdump.sh
index e7868ee..a5feabb 100755
--- a/localdump.sh
+++ b/localdump.sh
@@ -256,26 +256,33 @@
     # param  string  selection of items to select from
     # param  string  prompt to show
     function showSelectAndInput(){
-      local _selection="$1"
-      local _prompt="$2"
-  
-      local _lines
-      typeset -i _lines; _lines=$( grep -c "." <<< "$_selection" )
-  
-      if [ $_lines -eq "1" ]; then
-        echo "INFO: No interaction on a single choice. Using '$_selection'"
-        LASTINPUT="$_selection"
-        return 0
-      else
-  
-        echo "$_selection"
-        color.print input "${_prompt} >"
-        read -r LASTINPUT
-        if [ -z "$LASTINPUT" ]; then
-          echo "No input given. Aborting."
-          exit 1
-        fi
-      fi
+        local _selection="$1"
+        local _prompt="$2"
+    
+        local _lines
+        typeset -i _lines; _lines=$( grep -c "." <<< "$_selection" )
+    
+        case $_lines in
+            0)
+                color.echo error "ERROR no data for a further selection. Aborting."
+                echo
+                exit 1
+                ;;
+            1) 
+                echo "INFO: No interaction on a single choice. Using '$_selection'"
+                LASTINPUT="$_selection"
+                return 0
+                ;;
+            *)
+            echo "$_selection"
+            color.print input "${_prompt} >"
+            read -r LASTINPUT
+            if [ -z "$LASTINPUT" ]; then
+                echo "No input given. Aborting."
+                exit 1
+            fi
+            ;;
+        esac  
     }
 
     # ------------------------------------------------------------
@@ -358,7 +365,7 @@ EOH
     while [[ "$#" -gt 0 ]]; do case $1 in
         -h|--help)      showhelp; exit 0;;
         *) if grep "^-" <<< "$1" >/dev/null ; then
-                echo; echo "ERROR: Unknown parameter: $1"; echo; showhelp; exit 2
+                echo; color.echo error "ERROR: Unknown parameter: $1"; echo; showhelp; exit 2
             fi
             break;
             ;;
-- 
GitLab