-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch.sh
executable file
·34 lines (26 loc) · 923 Bytes
/
search.sh
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
#!/bin/bash
# Search all our repositories and their history for a string.
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
SCRIPTDIR="${BASH_SOURCE%/*}"
if [[ ! -d "$SCRIPTDIR" ]]; then SCRIPTDIR="$PWD"; fi
. "$SCRIPTDIR/includes.sh"
usage() {
echo "${COLOR_BOLD}Search all downloaded repositories, and history, for a string. Takes regex.${COLOR_RESET}"
echo "${COLOR_BOLD}Usage:${COLOR_GREEN}${COLOR_DIM}" $0 "<string>${COLOR_RESET}"
echo "${COLOR_BOLD}Example: ${COLOR_GREEN}${COLOR_DIM}"$0" sudofox${COLOR_RESET}"
exit;
}
[ -z "$1" ] && usage
REPOLIST=$(find "$SCRIPTDIR/repositories/" -maxdepth 2 -mindepth 2)
for repo in $REPOLIST; do
reponame=$(echo -n $repo|awk -F/ '{print $3"/"$4}')
echo "${COLOR_BOLD}Searching repository $reponame${COLOR_RESET}..."
pushd $repo
git --no-pager grep ''"$1"'' $(git rev-list --all)
popd
done