Skip to content

Instantly share code, notes, and snippets.

@jonowar
Last active May 5, 2016 23:30
Show Gist options
  • Save jonowar/9300bd0c958df1c58e0fe8caadd1463f to your computer and use it in GitHub Desktop.
Save jonowar/9300bd0c958df1c58e0fe8caadd1463f to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash -e
FROM=$1
TO=$2
if [ "$#" -ne 2 ]
then
echo "Usage: git refactor word_to_find word_to_replace"
exit 1
fi
echo "replacing all instances of $FROM with $TO"
for filename in $(git grep -l $FROM); do
echo "refactoring $filename"
sed s/$FROM/$TO/g $filename > $filename.bak
mv $filename.bak $filename
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment