Skip to content

Conversation

@pabs3
Copy link
Contributor

@pabs3 pabs3 commented Apr 20, 2018

Discover a separator when the / character is used in arguments.
Prevent running sed when the search pattern does not match any files.
Allow the flags to be passed as a third argument.

This is more in-line with how sed itself works.
@spacewander
Copy link
Collaborator

A little question:
What's the reason to allow the flag to be passed as the third option?

@pabs3
Copy link
Contributor Author

pabs3 commented Apr 20, 2018 via email

@spacewander
Copy link
Collaborator

@pabs3
I see.

bin/git-sed Outdated
sep=/
;;
esac
command="git grep -lz '$search' | xargs -0r sed -i 's$sep$search$sep$replacement$sep$flags'"
Copy link
Collaborator

@spacewander spacewander Apr 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-r option is a GNU extension. The xargs in OS X doesn't support it.
We have to remove it for the compatibility.

## SYNOPSIS

`git-sed` [ -c ] [ -f <flags> ] <search> <replacement>
`git-sed` [ -c ] [ -f <flags> ] <search> <replacement> [ <flags> ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pabs3
Copy link
Contributor Author

pabs3 commented Apr 21, 2018 via email

@spacewander
Copy link
Collaborator

I've updated my branch to add a mechanism to check if the xargs -r option exists and only use it when it does exist.

Does it cause different behaviors between different platforms?
Maybe we'd better check the output of git grep by ourselves?

@pabs3
Copy link
Contributor Author

pabs3 commented Apr 25, 2018 via email

@spacewander
Copy link
Collaborator

running git grep twice instead of once

Maybe we could store the result in a bash variable?

@pabs3
Copy link
Contributor Author

pabs3 commented Apr 25, 2018 via email

@spacewander
Copy link
Collaborator

@pabs3
OK.
Where is your latest change? I could not find it in this pull request.

@pabs3
Copy link
Contributor Author

pabs3 commented Apr 26, 2018 via email

@pabs3
Copy link
Contributor Author

pabs3 commented Apr 26, 2018 via email

bin/git-sed Outdated
sep=/
;;
esac
r=$(xargs -0r false < /dev/null > /dev/null 2>&1 && echo r)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use -r instead of -0r here, since we only want to test for -r?

pabs3 added 2 commits April 26, 2018 11:06
Prevents running sed when the search pattern does not match any files.

This results in sed printing an unnessecary warning:

$ git sed foo bar
sed: no input files
Prevents sed from returning an error for arguments containing filenames:

$ git sed src/foo.c src/bar.c
sed: -e expression tj#1, char 13: unknown option to `s'
@spacewander spacewander merged commit 4325238 into tj:master May 3, 2018
@spacewander
Copy link
Collaborator

@pabs3
Merged. Thank you!

@spacewander
Copy link
Collaborator

@pabs3
Will you submit another pull request to update the documentation?

@pabs3 pabs3 deleted the git-sed branch May 5, 2018 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants