Makefile: add pickrand
[cmccabe-bin] / xg
1 #!/usr/bin/env bash
2
3 die() {
4     echo $@
5     exit 1
6 }
7
8 if [ $# -eq 0 ]; then
9     echo "xg: locate a file in the source tree and display the full git log information."
10     echo "Usage: xg [filename-substring]"
11     echo "Example: xg /BlockReader.java"
12     echo "Example 2: xg test-patch"
13     echo
14     exit 1
15 fi
16
17 T=/tmp/$$.xg.tmp
18 trap "rm -rf ${T}; exit" INT TERM EXIT
19 find . -noleaf -xdev -name '*.java' -o -name '*.h' -o -name '*.c' \
20     -o -name '*.cpp' -o -name '*.cxx' -o -name '*.cc' -o -name '*.sh' | \
21         grep $@ > "${T}"
22 LINES=$(wc -l "${T}" | awk '{print $1}')
23 [ "${LINES}" -lt 1 ] && die "no results"
24 if [ "${LINES}" -gt 1 ]; then
25     echo "multiple results: "
26     cat "${T}"
27     exit 1
28 fi
29
30 F=$(cat "${T}")
31 git log --follow -p "${F}"