Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make xargs commands less dangerous #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

sente
Copy link

@sente sente commented Dec 30, 2016

Make xargs commands less dangerous

@echuber2
Copy link

echuber2 commented Dec 30, 2016

I think this is problematic because xargs does not seem to automatically eat the leading whitespace on each line if you specify the delimiter. Perhaps a more comprehensive solution would be to use the -Z parameter with grep, and eat leading whitespaces after each null in the result of that, before finally passing to xargs with -0? Just a thought.

For example, the current PR revision would do this on my end:

$ git branch --merged master | grep -v '^\*' | xargs -d '\n' -n 1 git branch -d
error: branch '  test1' not found.
error: branch '  test2' not found.

@sente
Copy link
Author

sente commented Dec 30, 2016

Reasonable, @echuber2.

grep -Z is on OSX (bsd grep) is shorthand for grep --decompress which is not the gnu grep -Z/--null functionality we're aiming for. I think the simplest solution here would be piping ... | sed 's/^ \+//g' | ... after the grep and before the xargs.

Thoughts?

@sente
Copy link
Author

sente commented Dec 30, 2016

I've updated the pull request.

@echuber2
Copy link

This seems to be duplicating the default behavior (pre-request). Perhaps I'm misunderstanding what this is meant to do? (By the way, I tried a variation with grep --null and it seems that it does not work together with -v, for some reason. The result will still be delimited with newlines.)

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.

None yet

2 participants