]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Slightly more interactive keyringer_get_file
authorSilvio Rhatto <rhatto@riseup.net>
Sun, 26 Jul 2015 17:00:12 +0000 (14:00 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sun, 26 Jul 2015 17:00:12 +0000 (14:00 -0300)
lib/keyringer/functions

index ab519b2fa83097b8397c7a7f4a23f95a57f51e61..70a107dabd193d8a399347e71b8eaf5deb981971 100755 (executable)
@@ -430,16 +430,18 @@ function keyringer_get_option {
 function keyringer_get_file {
   FILE="$(keyringer_filename "$RELATIVE_PATH/$1")"
 
-  if [ -z "$FILE" ]; then
-    keyringer_action_usage
-    exit 1
-  elif [ ! -f "$KEYDIR/$FILE" ]; then
+  if [ ! -f "$KEYDIR/$FILE" ]; then
     # Try to find a similar file
+    FILE=""
     count=0
     candidates=(`keyringer_exec find "$BASEDIR" | grep -i "$1" | grep -e '.asc$'`)
 
     if [ ! -z "$candidates" ]; then
-      echo "Could not find exact match for \"$1\", please choose one of the following secrets:"
+      if [ ! -z "$1" ]; then
+        echo "Could not find exact match for \"$1\""
+      fi
+
+      echo "Choose one of the following or type a pattern:"
       echo ""
 
       for candidate in ${candidates[@]}; do
@@ -452,15 +454,20 @@ function keyringer_get_file {
 
       if [[ "$option" =~ ^[0-9]+$ ]] && [ ! -z "${candidates[$option]}" ]; then
         FILE="$(keyringer_filename "$RELATIVE_PATH/${candidates[$option]}")"
-      else
-        echo "Invalid option"
-        exit 1
+      elif [ ! -z "$option" ]; then
+        keyringer_get_file $option
       fi
     else
-      echo "File not found: $KEYDIR/$FILE"
-      exit 1
+      echo "Nothing matches $option, try again."
+      keyringer_get_file
     fi
   fi
+
+  # Probably Ctrl-D was hit
+  if [ -z "$FILE" ]; then
+    echo ""
+    exit
+  fi
 }
 
 # Get a new file argument