1

I would like to do this:

git --git-dir=../navcl/.git format-patch -k -1 --stdout 607780ee9 \
  | nano \
  | git am -3 -k 

The issue is, in my other git dir, a file path is different, so I need to edit this in the patch. I could go via a file, but is there the option to edit the piping command in an editor? My use of nano here doesn't actually work, since I'm not aware how to get it to write to stdout.

  • 1
    If only there was a streaming editor >.>. If you can show us an example of the string(s) you would like to edit, including sample input and expected output, I'm sure someone can help you with sed. – jesse_b Oct 25 '19 at 13:32
  • My question is specifically about interactively editing a string using vim, nano or similar. Although in principle I could craft a sed replacement, of course. (It would be error-prone, though, because even if I edit the path I need to adapt, I cannot generally be sure that this path does not appear as part of the patch contents, where it might not need to be changed.) – Felix Dombek Oct 25 '19 at 13:34
  • 1
    Is there a reason you want to avoid using the POSIX standardized, and mostly universally available and extremely portable tool that was specifically created to solve the problem you have? – jesse_b Oct 25 '19 at 13:35
  • What do you mean by "I cannot generally be sure that this path does not appear as part of the patch contents". If you provide some examples I'm sure it can be done. – jesse_b Oct 25 '19 at 13:38
  • I can't share the actual patch with you, but I assume you're familiar with the git patch format? I need to change a path as it is interpreted by the patch parser; while leaving any string that is not interpreted by git's parser intact. In the general case, this might mean emulating a portion of the parser functionality in sed. (In particular, think about what happens when I check in a git patch into git, and patch the patch.) Not feasible. – Felix Dombek Oct 25 '19 at 14:02
  • I'm not that familiar with it, but as sed is turing complete, pretty much anything that is possible is possible in sed. Since so far everything about your task seems to be describing the standard use of sed, I'm sure it will be a relatively easy command to come up with. – jesse_b Oct 25 '19 at 14:03
  • I didn't say impossible, I said infeasible :D some things are just very easily identified by the human eye, while being very hard to derive a complete specification for. – Felix Dombek Oct 25 '19 at 14:04
  • @FelixDombek: You still haven't showed us what you are trying to do so I can't say, however I can pretty much guarantee you it isn't nearly as hard as you think it is. – jesse_b Oct 25 '19 at 14:05
  • @muru vipe is a great suggestion, thanks for sharing the link. – Felix Dombek Oct 25 '19 at 14:05
  • @Jesse_b I'm trying to learn something here. Yes, for my specific case I already came up with a sed command. But it's not reusable for more complicated cases. – Felix Dombek Oct 25 '19 at 14:07
  • I'm not sure what the back and forth is helping. We are here: You are trying to convince me your problem is more complicated than I think it is, but wont show me your problem. I don't believe your problem is as complicated as you think it is, and I will not believe it until you show me your problem. – jesse_b Oct 25 '19 at 14:09
  • Nothing prevents you from writing a script or function which saves the input to a temporary file, edits it, and then writes it out. Something like this: pipevi(){ t=$(mktemp) && cat >"$t" && vi "$t" </dev/tty >/dev/tty 2>&1 && cat "$t" && rm "$t"; }. –  Oct 25 '19 at 14:12

0 Answers0