#!/bin/sh
#
# Search a set of repos for specific words and return a list of URLS
# to the matching repos
#
if [ $# -lt 2 ]; then
printf "Usage: %s
[...]\n" $0
exit 1
fi
FOLDER="$1"
shift
WORDS="$@"
query=$(echo "$WORDS" | sed -E 's/\ /\|/g')
echo "$query"
cd "$FOLDER"
repos=$(find ./ -type d | grep -E "\/.*\/" | grep -Ei "$query" | \
sed -E 's/.\/([a-z]+)\//\1:\/\//1')
res=$(grep -Eric "$query" | grep -v ":0$" | sort -t ':' -rnk2 | \
sed -E 's/([a-z]+)\//\1:\/\//1;s/\/[^\/]*$//' )
echo "$repos" | grep -Ei "^[a-z]+://"
echo "--" >&2
echo "$res" | grep -Ei "^[a-z]+://"