mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 15:36:21 -04:00
git-sed: discover a separator when the / character is used in arguments
Prevents sed from returning an error for arguments containing filenames: $ git sed src/foo.c src/bar.c sed: -e expression #1, char 13: unknown option to `s'
This commit is contained in:
parent
c27a3505dc
commit
9785199036
19
bin/git-sed
19
bin/git-sed
|
|
@ -66,7 +66,22 @@ actual command:
|
|||
shift
|
||||
done
|
||||
|
||||
all="$search$replacement$flags"
|
||||
case "$all" in
|
||||
*/*)
|
||||
ascii="$(for((i=32;i<=127;i++)) do printf '%b' "\\$(printf '%03o' "$i")"; done)"
|
||||
sep="$(printf '%s' "$ascii" | tr -d "$all")"
|
||||
sep="$(printf %.1s "$sep")"
|
||||
if [ "X$sep" = "X" ] ; then
|
||||
echo 'could not find an unused character for sed separator character'
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
sep=/
|
||||
;;
|
||||
esac
|
||||
r=$(xargs -r false < /dev/null > /dev/null 2>&1 && echo r)
|
||||
command="git grep -lz '$search' | xargs -0$r sed -i 's/$search/$replacement/$flags'"
|
||||
git grep -lz "$search" | xargs -0"$r" sed -i "s/$search/$replacement/$flags"
|
||||
command="git grep -lz '$search' | xargs -0$r sed -i 's$sep$search$sep$replacement$sep$flags'"
|
||||
git grep -lz "$search" | xargs -0"$r" sed -i "s$sep$search$sep$replacement$sep$flags"
|
||||
do_commit
|
||||
|
|
|
|||
Loading…
Reference in a new issue