Last active
August 29, 2015 13:56
-
-
Save johngraham262/8846509 to your computer and use it in GitHub Desktop.
Git grep is a great search too, but I often find myself wanting to git grep for a term and then *replace* it too. With the "gsr" command, you can type in a search_term and a replace_term and it will search-->replace all matches. It's case-sensitive too.
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
# gsr = Git Search Replace | |
gsr() { | |
search_string=$1 | |
replace_string=$2 | |
if [ -z $search_string ] || [ -z $replace_string ] | |
then | |
echo "-- Git Search & Replace (gsr)" | |
echo "-- usage: gsr search_string replace_string" | |
else | |
git grep -l $search_string | xargs sed -i '' "s/$search_string/$replace_string/g" | |
echo "Crushed it." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment