From d6fb56eea0ecb26dd4fd7e310ba861478dec0903 Mon Sep 17 00:00:00 2001 From: ckrah <153164927+cktii@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:52:53 +0400 Subject: [PATCH] fix: only apply fuzzy matching if no exact match is found (#41) --- static.sh | 59 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/static.sh b/static.sh index 150d167..750ba43 100755 --- a/static.sh +++ b/static.sh @@ -85,27 +85,46 @@ dl() { continue fi - # Process each matching URL - echo "$asset_urls" | while read -r asset_url; do + # Use command substitution to capture output and check for exact match + exact_match=$(echo "$asset_urls" | while IFS= read -r asset_url; do filename=$(basename "$asset_url") - - # Check if it's an exact match or starts with the binary name - case "$filename" in - "$binary" | "$binary"*) - echo "[*] Downloading $filename..." - if _download "$asset_url" "$TEMP_DIR/$filename"; then - chmod +x "$TEMP_DIR/$filename" - echo " [+] Successfully installed $filename to $TEMP_DIR/$filename" - add_to_path - else - echo " [-] Error: Failed to download $filename." >&2 - fi - ;; - *) - # Skip files that don't match the criteria - ;; - esac - done + if [ "$filename" = "$binary" ]; then + echo "$asset_url" + break + fi + done) + + if [ -n "$exact_match" ]; then + # Process exact match + filename=$(basename "$exact_match") + echo "[*] Downloading $filename (exact match)..." + if _download "$exact_match" "$TEMP_DIR/$filename"; then + chmod +x "$TEMP_DIR/$filename" + echo " [+] Successfully installed $filename to $TEMP_DIR/$filename" + add_to_path + else + echo " [-] Error: Failed to download $filename." >&2 + fi + else + # Apply fuzzy matching + echo "[*] No exact match found. Applying fuzzy matching..." + echo "$asset_urls" | while IFS= read -r asset_url; do + filename=$(basename "$asset_url") + # Check if it starts with the binary name + case "$filename" in + "$binary"*) + echo "[*] Downloading $filename (fuzzy match)..." + if _download "$asset_url" "$TEMP_DIR/$filename"; then + chmod +x "$TEMP_DIR/$filename" + echo " [+] Successfully installed $filename to $TEMP_DIR/$filename" + add_to_path + else + echo " [-] Error: Failed to download $filename." >&2 + fi + ;; + esac + done + fi done }