]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Try to find a similar file at keyringer_get_file()
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 20 Feb 2014 03:22:03 +0000 (00:22 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 20 Feb 2014 03:22:03 +0000 (00:22 -0300)
lib/keyringer/actions/find
lib/keyringer/functions

index 92bec2557debfa408ed64d538ee4139c7392790b..21afc7a7096f392297c2f71d45f1ec8a1d12cbd5 100755 (executable)
@@ -15,5 +15,5 @@ shift
 ARGS="`echo "$*" | sed -e "s|^/*||"`"
 
 # Run find command
-cd "$KEYDIR/$RELATIVE_PATH" && find -iname "*$ARGS*"
+cd "$KEYDIR/$RELATIVE_PATH" && find -iname "*$ARGS*" | sed -e 's|^./||g'
 cd "$CWD"
index 5cc92b11ad1ac6974e607b37def6528d9be465fd..014c2c9e7f8a0e18af98b4023cf0c9773d85baba 100755 (executable)
@@ -411,8 +411,33 @@ function keyringer_get_file {
     keyringer_action_usage
     exit 1
   elif [ ! -f "$KEYDIR/$FILE" ]; then
-    echo "File not found: $KEYDIR/$FILE"
-    exit 1
+    # Try to find a similar file
+    count=0
+    candidates=(`keyringer_exec find "$BASEDIR" "$1" | grep -e '.asc$'`)
+
+    if [ ! -z "$candidates" ]; then
+      echo "Could not find exact match \"$1\", please chose one"
+      echo "of the following secrets:"
+      echo ""
+
+      for candidate in ${candidates[@]}; do
+        echo -e "\t[$count] $candidate"
+        let count++
+      done
+
+      echo ""
+      read -p "Enter option: " option
+
+      if [[ "$option" =~ ^[0-9]+$ ]] && [ ! -z "${candidates[$option]}" ]; then
+        FILE="$(keyringer_filename "$RELATIVE_PATH/${candidates[$option]}")"
+      else
+        echo "Invalid option"
+        exit 1
+      fi
+    else
+      echo "File not found: $KEYDIR/$FILE"
+      exit 1
+    fi
   fi
 }