summaryrefslogtreecommitdiff
path: root/search_repo
blob: ed9562da3a966a85764bf3a70f507801ecadb563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/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 <dir> <word> [<word>...]\n" $0
	exit 1
fi

FOLDER="$1"
shift
WORDS="$@"

query=$(echo "$WORDS" | sed -E 's/\ /\|/g')

cd "$FOLDER"

reponames=$(find ./ -type d | grep -E "\/.*\/" | grep -Ei "$query" | \
	sed -E 's/.\/([a-z]+)\//\1:\/\//1')

descrfiles=$(find ./ -type f -name 'DESCR' | tr '\n' ' ')
repodescr=$(grep -Eic "$query" ${descrfiles} | grep -v ":0$" | sort -t ':' -rnk2 | \
	sed -E 's/^\.\///;s/([a-z]+)\//\1:\/\//1;s/\/[^\/]*$//' )


readmefiles=$(find ./ -type f -iname 'readme*' | tr '\n' ' ')
readmes=$(grep -Eic "$query" ${readmefiles} | 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]+://"