Add xg
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Fri, 11 Jan 2013 05:36:46 +0000 (21:36 -0800)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Fri, 11 Jan 2013 05:36:46 +0000 (21:36 -0800)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

xg [new file with mode: 0755]

diff --git a/xg b/xg
new file mode 100755 (executable)
index 0000000..7edc734
--- /dev/null
+++ b/xg
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+die() {
+    echo $@
+    exit 1
+}
+
+if [ $# -eq 0 ]; then
+    echo "xg: locate a file in the source tree and display the full git log information."
+    echo "Usage: xg [filename-substring]"
+    echo "Example: xg /BlockReader.java"
+    echo "Example 2: xg test-patch"
+    echo
+    exit 1
+fi
+
+T=/tmp/$$.xg.tmp
+trap "rm -rf ${T}; exit" INT TERM EXIT
+find . -noleaf -xdev -name '*.java' -o -name '*.h' -o -name '*.c' \
+    -o -name '*.cpp' -o -name '*.cxx' -o -name '*.cc' -o -name '*.sh' | \
+        grep $@ > "${T}"
+LINES=$(wc -l "${T}" | awk '{print $1}')
+[ "${LINES}" -lt 1 ] && die "no results"
+if [ "${LINES}" -gt 1 ]; then
+    echo "multiple results: "
+    cat "${T}"
+    exit 1
+fi
+
+F=$(cat "${T}")
+git log --follow -p "${F}"