3

I'm trying to clean up my local set of git branches. There are quite a few, and I don't want to do git branch -D branchname for all of them. There's also no pattern that captures all and only the ones I want to kill. Then I remembered that I once saw someone pipe stdout into a buffer editor, and I thought that sounded perfect.

I'd like to take the output of git branch -l, pipe it into nano, edit the buffer, then (upon exiting nano) have the final buffer be supplied as the input into another command (specifically, xargs git branch -D).

Having played around for a while without luck, this has become an academic question related to editing buffers on the fly -- so, no git-specific solutions, please. I want to know how to edit buffers on the fly in bash one-liners, because it seems like the kind of bash-fu that could elevate me to godhood. Acceptable answers should also work when sandwiched between e.g. find and file or path operations (like rm, cat, or grep).

Tom
  • 8,509
  • 7
  • 49
  • 78

1 Answers1

3

The semi-colon is a perfectly acceptable operator.

git branch -l > /tmp/branches; nano /tmp/branches; whatever /tmp/branches; rm /tmp/branches
phs
  • 10,687
  • 4
  • 58
  • 84
  • This worked: `git branch -l > /tmp/branches; nano /tmp/branches; cat /tmp/branches | xargs git branch -D; rm /tmp/branches`; I'm still hoping to find a version that doesn't create files that need to be cleaned-up, but if nothing is forthcoming I'll mark this as an answer. Thanks! – Tom Jan 15 '14 at 21:23