Every now and then I want to recycle a command sequence I recently used, after I adapted it.
Let's imagine, yesterday I executed
foo 42
bar with some strange arguments
baz /my/most/beloved/folder
Now today I need to something similar like
foo -x 42
bar with some more strange arguments
baz /my/most/hated/folder
I can use ctrlR and foo
to find yesterday's command (maybe multiple times, because I use foo
in different contexts), change it and execute it. No problem so far. But now I'd love to quickly jump to the following line in history without repeating the lengthy search again (in reality often more than ten commands).
The fc
command of ksh
comes close to what I want, but it is not interactive: If I issue a dozen git
commands I may need to react to one of them responding other than expected (or executing the following commands will cause a mess).
The cmd
shell of MS Windows has a (for me usually annoying) behaviour: After executing a command from history, the up arrow doesn't take me to the last command in history, but to the last executed command, so after executing the foo
line again, arrow up and then arrow down would take me to the bar
line. This exact behaviour would not help me, because it only work when executing an unmodified line. If I modify it, the »history pointer« is set to the end again. But it would be the perfect solution to have such a bookmark in history, set it at the foo
line and have a key combination to take me back there or even better to the following line, moving the bookmark.
I guess I'm not the only one with such a need, but I did not find any solution to it. Currently I solve it by printing the relevant part of history and use the mouse to paste the line I need next, but this is clumsy and I don't ilke to switch between keyboard and mouse. And please get away with history expansion; I typically need to interactively edit the line, including tab expansion.
Do you know any solution, preferably for zsh
?
fc <histroy-number-1> <history-number-2>
in zsh opens that range of commands in the history in an editor. You can then edit, save and quit, at which point it will execute the edited commands. Is that close to what you want?fc
gets close to it, but is not interactive, which is a problem for many cases. I can't use tab-completion and I can't stop following commands if something went wrong.; read
to the end of each line (easy to do in an editor) and then you'll have to press Enter to continue after each command, and pressing Ctrl-C instead would cancel and stop progressing to the next commandfc
solution. Feel free to add this as an answer. I'll accept if no one can give something closer to my needs on the silver platter.