diff options
-rwxr-xr-x | index_repo | 24 | ||||
-rwxr-xr-x | search_repo | 17 |
2 files changed, 33 insertions, 8 deletions
diff --git a/index_repo b/index_repo new file mode 100755 index 0000000..f1f28d7 --- /dev/null +++ b/index_repo @@ -0,0 +1,24 @@ +#!/bin/sh + +# +# Index a repo +# + +REPOIDX="repo_idx.txt" +DSCRIDX="descr_idx.txt" +RDMEIDX="readme_idx.txt" + +if [ $# -eq 0 ]; then + start="./" +else + start="$@" +fi + +find $start -type d | grep -E "\/.*\/" | sed -E 's/.\/([a-z]+)\//\1:\/\//1' \ + > ${REPOIDX} + +find $start -type f -name 'DESCR' | tr '\n' ' ' \ + > ${DSCRIDX} + +find $start -type f -iname 'readme*' | tr '\n' ' ' \ + > ${RDMEIDX} diff --git a/search_repo b/search_repo index ed9562d..05409ce 100755 --- a/search_repo +++ b/search_repo @@ -5,6 +5,11 @@ # to the matching repos # + +REPOIDX="repo_idx.txt" +DSCRIDX="descr_idx.txt" +RDMEIDX="readme_idx.txt" + if [ $# -lt 2 ]; then printf "Usage: %s <dir> <word> [<word>...]\n" $0 exit 1 @@ -18,16 +23,12 @@ 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/\/[^\/]*$//' ) +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/\/[^\/]*$//' ) -readmefiles=$(find ./ -type f -iname 'readme*' | tr '\n' ' ') -readmes=$(grep -Eic "$query" ${readmefiles} | grep -v ":0$" | sort -t ':' -rnk2 | \ +readmes=$(grep -Eic "$query" $(cat $RDMEIDX) | grep -v ":0$" | sort -t ':' -rnk2 | \ sed -E 's/^\.\///;s/([a-z]+)\//\1:\/\//1;s/\/[^\/]*$//' ) |