Domanda

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).

È stato utile?

Soluzione

The semi-colon is a perfectly acceptable operator.

git branch -l > /tmp/branches; nano /tmp/branches; whatever /tmp/branches; rm /tmp/branches
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top