-
-
Save jhult/c3ddb9db38a2f73ccfccbf4186c75b39 to your computer and use it in GitHub Desktop.
rgr command - Find and Replace with rg on macOS
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
#!/bin/zsh | |
rgr() { | |
# find and replace | |
regex="s?${1}?${2}?g;" | |
rg $1 -l | xargs sed -i.rgr_backup $regex | |
# delete backups | |
find . -name "*.rgr_backup" -print0 | xargs rm | |
} | |
# Original based on ag (The Silver Searcher): https://gist.github.com/jefflombard/c016d3a929ebf5dd1da5bcaddc64e72a | |
# This code is based on rg (ripgrep): https://gist.github.com/jhult/c3ddb9db38a2f73ccfccbf4186c75b39 | |
# Usage on macOS | |
# 1. Install rg - https://github.com/BurntSushi/ripgrep (`brew install ripgrep`) | |
# 2. Copy lines 3 - 9 into your .zshrc | |
# 3. Go to the target directory and call with "rgr" | |
# Example | |
# Replace "test" with "hello": "rgr test hello" |
FYI for anyone: I wrote a really robust ripgrep wrapper that allows full replacement via -R
. See rgr.sh
here: https://github.com/ElectricRCAircraftGuy/ripgrep_replace
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/facebookincubator/fastmod