From a1af45d177562a59ec5cf74aae6f48116e6a5fa3 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 21 Sep 2026 21:52:54 +0500 Subject: git: proper sed usage from text.sh --- %HOME%/.bash_utils/git.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/%HOME%/.bash_utils/git.sh b/%HOME%/.bash_utils/git.sh index 3542ed6..c7a2cbd 100644 --- a/%HOME%/.bash_utils/git.sh +++ b/%HOME%/.bash_utils/git.sh @@ -81,7 +81,15 @@ git_replace() ( readonly str="$1" readonly sub="$2" - git grep --files-with-matches -- "$str" | xargs sed -i "s/$str/$sub/g" + local path + local -a paths=() + + git grep -z --files-with-matches -- "$str" | + while IFS= read -d '' -r path; do + paths+=("$path") + done + + file_replace "$str" "$sub" ${paths[@]+"${paths[@]}"} ) git_replace_word() ( @@ -95,5 +103,13 @@ git_replace_word() ( readonly str="$1" readonly sub="$2" - git grep --files-with-matches --word-regexp -- "$str" | xargs sed -i "s/\b$str\b/$sub/g" + local path + local -a paths=() + + git grep -z --files-with-matches -- "$str" | + while IFS= read -d '' -r path; do + paths+=("$path") + done + + file_replace_word "$str" "$sub" ${paths[@]+"${paths[@]}"} ) -- cgit v1.3