Skip to content

Instantly share code, notes, and snippets.

@torpedoallen
Last active February 24, 2022 15:09
Show Gist options
  • Save torpedoallen/3c4d9832794922cdb88f to your computer and use it in GitHub Desktop.
Save torpedoallen/3c4d9832794922cdb88f to your computer and use it in GitHub Desktop.
git sub
#!/bin/bash
# author: torpedoallen
# usage: find and replace
# how-to: put the file into your PATH like /usr/local/bin and make it executable.
# reminders: the default sed command will no longer work fine with -i argument, please replace with gnu-sed
if [ -z "$3" ]; then git grep -zl "$1" | xargs -0 sed -i "s/$1/$2/g"; else git grep -zl "$1" -- $3 | xargs -0 sed -i "s/$1/$2/g"; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment