Add bin/replace
This commit is contained in:
parent
49b59a83e2
commit
c5dd7544a1
14
bin/replace
Executable file
14
bin/replace
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Find and replace by a given list of files.
|
||||||
|
#
|
||||||
|
# replace foo bar **/*.rb
|
||||||
|
|
||||||
|
find_this="$1"; shift
|
||||||
|
replace_with="$1"; shift
|
||||||
|
|
||||||
|
items=$(ag -l --nocolor "$find_this" "$@")
|
||||||
|
temp="${TMPDIR:-/tmp}/replace_tmp.$$"
|
||||||
|
for item in $items; do
|
||||||
|
sed "s/$find_this/$replace_with/g" "$item" > "$temp" && mv "$temp" "$item"
|
||||||
|
done
|
Loading…
Reference in a new issue