Last active
October 22, 2015 02:42
-
-
Save jeebak/f9088cede18d31f2d3a0 to your computer and use it in GitHub Desktop.
Apply the pie, on the fly
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
#!/usr/bin/env bash | |
# | |
# https://gist.github.com/jeebak/f9088cede18d31f2d3a0 | |
# | |
# Added to: https://github.com/unixorn/git-extra-commands | |
# Further updates will be there. | |
# | |
[[ $# -ne 2 ]] && echo "Usage: git pie-ify pattern replacement" 1>&2 && exit 1 | |
pattern="$(sed 's;/;\\/;g' <<< "$1")" | |
replacement="$(sed 's;/;\\/;g' <<< "$2")" | |
while read -r file; do | |
if [[ -f "$file" ]]; then | |
echo "Processing: '$file'" | |
# TODO: fall back to sed, if perl's not available, accounting for different | |
# (osx/linux) versions. | |
perl -p -i -e 's/'"$pattern"'/'"$replacement"'/g' "$file" | |
fi | |
done <<< "$(git grep --name-only "$pattern")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment