diff options
| author | Federico Angelilli <code@fedang.net> | 2024-01-01 18:52:12 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-01-01 18:52:12 +0100 |
| commit | af93c4f747a02766d62a0f971ccc6f4d97a8a520 (patch) | |
| tree | a036156d92ae2b0e841e0af41e2048eafb62dd27 /crypt.sh | |
| parent | fbc11cb83d25ef801519c2f3adfd97044f53648e (diff) | |
Rewrite confirm_file function
Diffstat (limited to 'crypt.sh')
| -rwxr-xr-x | crypt.sh | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -300,7 +300,6 @@ check_file() { readarray -t -O ${#matches[@]} matches < <(find "$CRYPT_PATH/" -path '*/.git' -prune -o -path "$CRYPT_PATH/${path%/}${entries_ext[$i]}.gpg" -print) done - #printf "%q\n" "${matches[@]}" >&2 case ${#matches[@]} in 0) [[ "$2" == "noask" ]] || confirm_file "$path" ;; 1) [[ "${matches[0]}" =~ $CRYPT_PATH/(.*)\.gpg ]] && echo "${BASH_REMATCH[1]}" ;; @@ -309,15 +308,22 @@ check_file() { } confirm_file() { - local ans="$1" name="${1##*/}" dir="$(dirname -- "$path")" - while true; do - ans="${ans%.gpg}" - local entry=$(find_entry "$dir/${ans#$dir}.gpg") + local entry=$(find_entry "${1%.gpg}.gpg") ans="" + + [[ ($entry -eq 0 && ${#entries_ext[@]} -eq 3) || $entry -eq 1 ]] && echo "$1" && return - [[ ($entry -ne 0 || ${#entries_ext[@]} -eq 3) && $entry -ne 1 && "$ans" =~ ($dir/)?($name.*) ]] && echo "$dir/${BASH_REMATCH[2]}" && return + while true; do + for ((i = 3; i < ${#entries_name[@]}; i++)); do + echo "${entries_ext[$i]}) $(_color ${entries_color[$i]})${entries_name[$i]}$(_color reset)" >&2 + done + read -r -p "Select one of the valid entries: " ans - # TODO: Make something that given the entry name automatically appends the extension (and doesn't allow you to change name) - read -r -p "Enter a file with a valid extension: " ans + for ((i = 3; i < ${#entries_name[@]}; i++)); do + if [[ "$ans" == "${entries_ext[$i]}" || "$ans" == "${entries_name[$i]}" ]]; then + echo "${1%.}.$ans" + return + fi + done done } |
