Created
July 12, 2012 23:24
-
-
Save lonnen/3101795 to your computer and use it in GitHub Desktop.
git grep and git blame. two great tastes that taste great together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from i8ramin - http://getintothis.com/blog/2012/04/02/git-grep-and-blame-bash-function/ | |
# runs git grep on a pattern, and then uses git blame to who did it | |
ggb() { | |
git grep -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done | |
} | |
# small modification for git egrep bash | |
geb() { | |
git grep -E -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done | |
} |
fish shell:
function git_grep_blame -d "git grep + git blame"
set -l IFS :
command git grep -En $argv[1] | while read -l file line code
git blame -f -L $line,$line $file | grep -E --color "$argv[1]|\$"
end
end
Love the fish shell, thanks! Unfortunately, can't pass grep arguments.
I use this alias in .gitconfig
:
grame = "!r() { git grep -n $1 $2 | while IFS=: read i j k; do echo $i; git blame -f -L $j,$j $i; done }; r"
(To see the filename, I added echo $i
to @henrik242's command mentioned above.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A little
-f
makes sure the file name is always printed, andcat
is not necessary: