Last active
December 29, 2015 09:39
-
-
Save victormier/7651313 to your computer and use it in GitHub Desktop.
Simple git grep replace for bash written in ruby. Replaces all instances of a string in any tracked file. Based on https://gist.github.com/jcamenisch/1671995 Allows strings with whitespaces.
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
#!/usr/bin/env ruby | |
if ARGV.length != 2 | |
puts "Usage:" | |
puts ' gg_replace term replacement' | |
puts | |
puts 'Example:' | |
puts ' gg_replace "bad cappuchino" "fine cappuccino"' | |
exit | |
end | |
find = ARGV[0] | |
replace = ARGV[1] | |
files = `git grep -l '#{find}'`.split("\n") | |
files.each do |file| | |
`sed -e 's/#{find}/#{replace}/g' -i '' #{file}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reminder: scape forward slashes