Update bin/replace script for better portability

The existing implementation of the `replace` script does not work on
GNU/Linux due to differences in the implementation of `sed`. This change
reworks the process of the replacement to create temporary files,
apply the changes to the files, and then move them into place. It will
improve the script's portability for more OSes.
This commit is contained in:
pedro-nonfree 2015-12-11 10:56:17 -05:00 committed by Geoff Harcourt
parent 68b6446b9a
commit 2d9e8bf0e8

View file

@ -9,4 +9,8 @@ shift
replace_with="$1"
shift
ag -l --nocolor "$find_this" "$@" | xargs sed -i '' "s/$find_this/$replace_with/g"
items=$(ag -l --nocolor "$find_this" "$@")
temp="${TMPDIR:-/tmp}/replace_temp_file.$$"
for item in $items; do
sed "s/$find_this/$replace_with/g" "$item" > "$temp" && mv "$temp" "$item"
done