by a3n · 11y ago · 0 comments
Very often I do something like this in quick succession. Command line editing makes this trivial.
$ find . -name "*blarg*.cpp"
# Some output that looks like what I'm looking for.
# Run the same find again in a process, and grep for something.
$ grep -i "blooey" $(find . -name "*blarg*.cpp")
# Yep, those are the files I'm looking for, so dig in.
# Note the additional -l in grep, and the nested processes.
$ vim $(grep -il "blooey" $(find . -name "*blarg*.cpp")) $ find . -name "*blarg*.cpp"
$ grep -i "blooey" $(!!)
$ vim $(!! -l)
Granted, you can only append new arguments and using the other ! commands will often be less practical than editing. Still, it's amazing how frequently this is sufficient.I've always thought it'd be nice if there was a `set` option or something similar that would make bash record command lines and cache output automatically in implicit variables, so that it doesn't re-run the commands. The semantics are definitely different and you wouldn't want this enabled at all times, but for certain kinds of sessions it would be very handy.
EDIT: lazyjones beat me to it.
I'm lazy, so I typically do this (2nd step) to avoid the extra key strokes necessary for editing:
$ grep -i "blooey" $(!!)
Also very useful for avoiding editing in order to do something else with the same argument as in the previous command: !$, i.e.: $ foo myfile
$ bla !$ $ find . -name '*blarg*.cpp' | grep -li blooey | vi -