-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabq.sh
executable file
·66 lines (56 loc) · 1.55 KB
/
abq.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# Wrapper (command line interface) for the abq.mk file.
set -eu
prog=${0##*/}
makefile=${0%.sh}.mk
version=0.3
grep_options=( --ignore-case --text )
make_options=( --quiet --file "$makefile" )
debug=false
usage () {
echo "$prog [-x] search terms"
echo "$prog -c"
echo "$prog -s"
echo "$prog -h"
echo "$prog -v"
}
help () {
echo "Search the little brothers data base for a matching email address."
echo "Options: -x for debugging, -h for help, -v for version."
echo "With -c the cache is cleared."
echo "Search terms are used by grep(1) in case insensitive mode."
}
# Grep for the logical AND of several search terms. This is not possible with
# plain grep (or plain regex) which only provide logical OR.
grep_chain () {
if [[ $# -eq 1 ]]; then
grep "${grep_options[@]}" --regexp="$1"
else
local pattern=$1
shift
grep "${grep_options[@]}" --regexp="$pattern" | grep_chain "$@"
fi
}
while getopts chsvx FLAG; do
case $FLAG in
c) echo Clearing cache. >&2; make "${make_options[@]}" clear-cache; exit;;
h) usage; echo; help; exit;;
s) echo Statistics:; make "${make_options[@]}" cache-statistics; exit;;
v) echo "$prog $version"; echo "Using $(grep --version|head -n 1)"; exit;;
x) debug=true; set -x;;
*) usage >&2; exit 2;;
esac
done
shift $((OPTIND - 1))
if [ $# -lt 1 ]; then
usage >&2
exit 2
fi
if "$debug"; then
make_options=( "${make_options[@]/--quiet/--debug}" )
fi
make \
--no-builtin-rules \
--no-builtin-variables \
"${make_options[@]}"
grep_chain "$@" < ~/.cache/abq/abq