From 403836416d6b3dee3e868a1cb2d5e9ca8fada211 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:50:29 +0000 Subject: [PATCH] Refactor `fallback_search` in `idstack-learnings-search` to remove duplication Co-authored-by: savvides <1580637+savvides@users.noreply.github.com> --- bin/idstack-learnings-search | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/bin/idstack-learnings-search b/bin/idstack-learnings-search index 94cc40f..29e5c70 100755 --- a/bin/idstack-learnings-search +++ b/bin/idstack-learnings-search @@ -36,6 +36,16 @@ fi [ -z "$SOURCES" ] && exit 0 +fallback_search() { + if [ -n "$KEYWORD" ]; then + cat $SOURCES 2>/dev/null | grep -i "$KEYWORD" | tail -"$LIMIT" + elif [ -n "$TYPE" ]; then + cat $SOURCES 2>/dev/null | grep "\"type\":\"$TYPE\"" | tail -"$LIMIT" + else + cat $SOURCES 2>/dev/null | tail -"$LIMIT" + fi +} + if command -v python3 &>/dev/null; then python3 -c " import json, sys @@ -71,20 +81,8 @@ for m in matches[-limit:]: print(m) " 2>/dev/null || { # Fallback: basic grep - if [ -n "$KEYWORD" ]; then - cat $SOURCES 2>/dev/null | grep -i "$KEYWORD" | tail -"$LIMIT" - elif [ -n "$TYPE" ]; then - cat $SOURCES 2>/dev/null | grep "\"type\":\"$TYPE\"" | tail -"$LIMIT" - else - cat $SOURCES 2>/dev/null | tail -"$LIMIT" - fi + fallback_search } else - if [ -n "$KEYWORD" ]; then - cat $SOURCES 2>/dev/null | grep -i "$KEYWORD" | tail -"$LIMIT" - elif [ -n "$TYPE" ]; then - cat $SOURCES 2>/dev/null | grep "\"type\":\"$TYPE\"" | tail -"$LIMIT" - else - cat $SOURCES 2>/dev/null | tail -"$LIMIT" - fi + fallback_search fi