From dd7204e6033b4122cfcc3c4aa7db5f9ea17df243 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 21 May 2023 18:41:37 +0200 Subject: git.sh: add git_replace{_word} --- %HOME%/.bash_utils/git.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/%HOME%/.bash_utils/git.sh b/%HOME%/.bash_utils/git.sh index 5095610..23f9ee1 100644 --- a/%HOME%/.bash_utils/git.sh +++ b/%HOME%/.bash_utils/git.sh @@ -111,3 +111,33 @@ branch_backup() ( --remote="$repo_dir" \ HEAD ) + +git_replace() ( + set -o errexit -o nounset -o pipefail + shopt -s inherit_errexit lastpipe + + if [ "$#" -ne 2 ]; then + echo "usage: ${FUNCNAME[0]} STR SUB" 1>&2 + exit 1 + fi + + readonly str="$1" + readonly sub="$2" + + git grep --files-with-matches -- "$str" | xargs sed -i "s/$str/$sub/g" +) + +git_replace_word() ( + set -o errexit -o nounset -o pipefail + shopt -s inherit_errexit lastpipe + + if [ "$#" -ne 2 ]; then + echo "usage: ${FUNCNAME[0]} STR SUB" 1>&2 + exit 1 + fi + + readonly str="$1" + readonly sub="$2" + + git grep --files-with-matches --word-regexp -- "$str" | xargs sed -i "s/\b$str\b/$sub/g" +) -- cgit v1.2.3