git-sed: Allow the flags to be passed as a third argument

This is more in-line with how sed itself works.
This commit is contained in:
Paul Wise 2018-04-20 11:24:05 +08:00
parent 1b94ca130c
commit ee14220f66
No known key found for this signature in database
GPG key ID: 3116BA5E9FFA69A3
2 changed files with 7 additions and 4 deletions

View file

@ -2,10 +2,10 @@
usage() {
cat <<EOF
usage: git sed [ -c ] [ -f <flags> ] <search> <replacement>
usage: git sed [ -c ] [ -f <flags> ] <search> <replacement> [ <flags> ]
Run git grep and then send results to sed for replacement with the
given flags, if -f is provided.
given flags, if they are provided via -f or as the third argument.
Also runs git commit if -c is provided.
EOF
@ -54,6 +54,8 @@ actual command:
search="$1"
elif [ "X$replacement" = "X" ]; then
replacement="$1"
elif [ "X$flags" = "X" ]; then
flags="$1"
else
usage
echo "too many arguments: $1"

View file

@ -3,12 +3,12 @@ git-sed(1) -- replace patterns in git-controlled files
## SYNOPSIS
`git-sed` [ -c ] [ -f <flags> ] <search> <replacement>
`git-sed` [ -c ] [ -f <flags> ] <search> <replacement> [ <flags> ]
## DESCRIPTION
Run git grep and then send results to sed for replacement with the
given flags, if -f is provided.
given flags, if they are provided via -f or as the third argument.
Also runs git commit if -c is provided.
@ -20,6 +20,7 @@ Also runs git commit if -c is provided.
detailing the exact command ran. will fail if there are unstaged
changes.
&lt;flags&gt;
-f &lt;flags&gt;
will use the given regex flags in the sed command (for example "g"