Skip to content

Instantly share code, notes, and snippets.

@jeebak
Last active October 22, 2015 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeebak/f9088cede18d31f2d3a0 to your computer and use it in GitHub Desktop.
Save jeebak/f9088cede18d31f2d3a0 to your computer and use it in GitHub Desktop.
Apply the pie, on the fly
#!/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