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:
parent
68b6446b9a
commit
2d9e8bf0e8
1 changed files with 5 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue