Skip to content

Instantly share code, notes, and snippets.

@jefflombard
Last active October 12, 2021 13:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jefflombard/c016d3a929ebf5dd1da5bcaddc64e72a to your computer and use it in GitHub Desktop.
Save jefflombard/c016d3a929ebf5dd1da5bcaddc64e72a to your computer and use it in GitHub Desktop.
agr command - Find and Replace with ag on Mac OSX
#!/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