helm/bin/replace.sh

15 lines
329 B
Bash
Raw Normal View History

2016-03-03 07:46:27 -08:00
#!/bin/sh
#
# Find and replace by a given list of files.
#
# replace foo bar **/*.rb
find_this="$1"; shift
replace_with="$1"; shift
2016-11-21 20:58:53 -08:00
items=( $(ag -l --nocolor "$find_this" "$@") )
2016-03-03 07:46:27 -08:00
temp="${TMPDIR:-/tmp}/replace_tmp.$$"
2016-11-21 20:58:53 -08:00
for item in ${items[@]}; do
2016-03-03 07:46:27 -08:00
sed "s/$find_this/$replace_with/g" "$item" > "$temp" && mv "$temp" "$item"
done