/
git-diff-grep
executable file
·63 lines (52 loc) · 1.39 KB
/
git-diff-grep
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
#!/bin/bash
# Usage: git-diff-grep <revs-number> <query>
# Example: "git-diff-grep 10 login_required" will grep for
# login_required in the last 10 commits diffs
# lifted from: https://github.com/oscardelben/git-diff-grep
#!/bin/bash
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
# Get rid of multiple whitespaces
function trim {
echo $*
}
git log --pretty=oneline -$1 | awk '{print $1}' |
while read rev; do
git diff $rev |
grep -q "$2"
if [ $? -eq 0 ]
then
echo " ${txtylw}commit $rev${txtrst}"
git show -s --format=" Author: %cn <%cE>" $rev
git show -s --format=" Date: %cd" $rev
git show -s --format=" %s" $rev
echo
git_diff=$(git diff $rev | grep "$2")
echo "$git_diff" | while read line
do
add_remove=$(echo $line | grep '^[-+]')
if [ "$add_remove" ]; then
add=$(echo $line | grep '^[-]')
if [ "$add" ]; then
color=$txtred
else
color=$txtgrn
fi
else
color=$txtrst
fi
echo " ${color}$(trim $line)${txtrst}"
done
echo
echo
fi
done