diff options
| author | Egor Tensin <egor@tensin.name> | 2026-09-21 21:52:54 +0500 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-09-21 21:52:54 +0500 |
| commit | a1af45d177562a59ec5cf74aae6f48116e6a5fa3 (patch) | |
| tree | eb2afba00f6dc05a533fefb2fbc06f24e6378f6f | |
| parent | bash: dedupe function preludes (diff) | |
| download | linux-home-a1af45d177562a59ec5cf74aae6f48116e6a5fa3.tar.gz linux-home-a1af45d177562a59ec5cf74aae6f48116e6a5fa3.zip | |
git: proper sed usage from text.sh
| -rw-r--r-- | %HOME%/.bash_utils/git.sh | 20 |
1 files 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[@]}"} ) |
