From c5dd7544a165842e778c1adb6f766ab2d17a5f35 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 3 Mar 2016 10:46:27 -0500 Subject: [PATCH] Add bin/replace --- bin/replace | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 bin/replace diff --git a/bin/replace b/bin/replace new file mode 100755 index 00000000..1601829b --- /dev/null +++ b/bin/replace @@ -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