Last active
October 12, 2021 13:36
-
-
Save jefflombard/c016d3a929ebf5dd1da5bcaddc64e72a to your computer and use it in GitHub Desktop.
agr command - Find and Replace with ag on Mac OSX
This file contains 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/sh | |
agr () { | |
# find and replace | |
regex=s/${1}/${2}/g; | |
ag $1 -l | xargs sed -i.agr_backup $regex; | |
# delete backups | |
ag -G .agr_backup -l | xargs rm | |
} | |
# USAGE ON MAC OSX | |
# 1. Install ag - https://github.com/ggreer/the_silver_searcher | |
# 2. Copy lines 3 - 9 into your .bash_profile | |
# 3. go to target directory and call with "agr" | |
# EXAMPLE | |
# Replace "test" with "hello" using "agr test hello" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment