bin/replace: refactor

This commit is contained in:
Henrik Lissner 2017-04-22 01:59:04 -04:00
parent a760a43502
commit 19bd70185d

View file

@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
#
# Find and replace by a given list of files.
#
@ -8,7 +8,6 @@ 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"
sed -i "s/${find_this}/${replace_with}/g" "$item"
done