Skip to content

Commit

Permalink
Update bin/replace script for better portability
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pedro-nonfree authored and geoffharcourt committed Dec 11, 2015
1 parent 68b6446 commit 2d9e8bf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/replace
Expand Up @@ -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

0 comments on commit 2d9e8bf

Please sign in to comment.