Efficient pattern search for multiple local git repos
This is very useful to use your own code as reference.
- Store all your local git repos in
~/code
. You can change this but be sure to update point 3 accordingly. - Install parallel. In macosx:
brew install parallel
-
Add this to your
~/.bashrc
or~/.zshrc
grepcode() { find ~/code -type d -name .git | parallel "cd {.} && git grep --color -I --full-name -i '$@' | sed 's@^\(.*\):@{.}\1: @'"; }
source ~/.bashrc
orsource ~/.zshrc
Enjoy! eg:
grepcode 'belongs_to.*blahblah'
Written by Daniel Cadenas
Related protips
2 Responses
Had to add a semicolon to make it work in my ~/.profile on Mac OS X 10.8.4 but then it's great! Thanks for sharing
grepcode() {
find ~/dev/repos -type d -name .git | parallel "cd {.} && git grep --color -I --full-name -i '$@' | sed 's@^\(.*\):@{.}\1: @'";
}
over 1 year ago
·
Thanks, I just added the ;
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#