#!/bin/sh
#
# Search a set of repos for specific words and return a list of URLS
# to the matching repos
#
REPOIDX="repo_idx.txt"
DSCRIDX="descr_idx.txt"
RDMEIDX="readme_idx.txt"
if [ $# -lt 2 ]; then
printf "Usage: %s
[...]\n" $0
exit 1
fi
FOLDER="$1"
shift
WORDS="$@"
query=$(echo "$WORDS" | sed -E 's/\ /\|/g')
cd "$FOLDER"
reponames=$( grep -Ei "$query" $REPOIDX)
repodescr=$(grep -Eic "$query" $(cat $DSCRIDX) | grep -v ":0$" | sort -t ':' -rnk2 | \
sed -E 's/^\.\///;s/([a-z]+)\//\2:\/\//1;s/\/[^\/]*$//' )
readmes=$(grep -Eic "$query" $(cat $RDMEIDX) | grep -v ":0$" | sort -t ':' -rnk2 | \
sed -E 's/^\.\///;s/([a-z]+)\//\1:\/\//1;s/\/[^\/]*$//' )
echo "--URL" >&2
echo "$reponames" | grep -Ei "^[a-z]+://"
echo "--DESCR" >&2
echo "$repodescr" | grep -Ei "^[a-z]+://"
echo "--README" >&2
echo "$readmes" | grep -Ei "^[a-z]+://"