Skip to content

Instantly share code, notes, and snippets.

@bhenderson
Created June 30, 2021 14:20
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 bhenderson/cc39407b87714038c4d033ac9e9532e1 to your computer and use it in GitHub Desktop.
Save bhenderson/cc39407b87714038c4d033ac9e9532e1 to your computer and use it in GitHub Desktop.
perl pie but only act on git files. Optional second parameter can dramatically speed up the replacement.
#!/bin/bash
set -euo pipefail
###
# Usage
#
# git pie <perl-script> [git grep options]
script=$1; shift
# if no grep options, search for `.` which will return all files.
[ $# = 0 ] && set -- .
# -z support files with weird characters/spaces
# -I don't search binary files
git grep --name-only -z -I "$@" | xargs -0 perl -pi -e "$script"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment