-
-
Save frangio/462d5563d88a2982b6c23e6d2e72e93c to your computer and use it in GitHub Desktop.
ripsed: use ripgrep as a sed replacement. requires sponge from moreutils
This file contains hidden or 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 | |
set -o errexit -o pipefail | |
if [ "$#" -eq 0 ] | |
then | |
echo "usage: rs PATTERN REPLACEMENT [PATH...]" > /dev/stderr | |
exit 1 | |
fi | |
pattern="$1" | |
replacement="$2" | |
shift 2 | |
paths=("$@") | |
rg -l "$pattern" "${paths[@]}" | while IFS=$'\n' read -r file; do | |
rg --passthru "$pattern" --replace "$replacement" "$file" | sponge "$file" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment