diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-21 18:41:37 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-21 18:41:37 +0200 |
commit | dd7204e6033b4122cfcc3c4aa7db5f9ea17df243 (patch) | |
tree | 49704196728f3b8e8523deb86eaeab25553dd6fc | |
parent | bash: support copy alias on multiple platforms (diff) | |
download | linux-home-dd7204e6033b4122cfcc3c4aa7db5f9ea17df243.tar.gz linux-home-dd7204e6033b4122cfcc3c4aa7db5f9ea17df243.zip |
git.sh: add git_replace{_word}
Diffstat (limited to '')
-rw-r--r-- | %HOME%/.bash_utils/git.sh | 30 |
1 files changed, 30 insertions, 0 deletions
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" +) |