I often run searches on my source code repo like this:
ack -l "foo bar" .
The searches can take 10-60 seconds and produce output like this:
path/to/file1
path/to/file2
path/to/file3
I frequently use this alias to open all of the files found in vim:
alias go='gvim `fc -s` -p'
This works OK, but fc -s
reruns the previous command, which can take seconds or minutes.
It would be very useful to append something like this to every command I run interactively:
| tee /tmp/lastCommand to all commands.
This way, if the output reveals itself to be useful, then I can do something else to it.
Example usage:
Type:
find . -type f
Which executes the following:
find . -type f | tee $lastOutLocation # Where lastOutputLocation=/tmp/lastOutput
You could then use something like this, to filter the previous command:
lastOut | grep "SomeString" # Where lastOut is an alias to cat $lastOutputLocation
Is there a mechanism I can use to do something like this? I don't think that aliases expose this kind of behaviour.
Potential Hurtles:
- Getting something that works with compound commands:
echo 'baz' ; echo 'bar'
- Figure out how to modify the command the user typed before running it
- Ignore things like interactive input. Don't want to capture password prompts
Possible solutions, I am currently exploring:
- Using TRAP and shopt as in this answer
run
) that would call the quoted command you want to run. Then you'drun 'find . -type f'
and the script would executefind . -type f | tee $lastOutLocation
. Note that I used quotes to allow multiple commands as you mentioned. – Julie Pelletier Jan 13 '17 at 17:36script
) command – Jeff Schaller♦ Jan 13 '17 at 17:38tee
(or anything else) wouldn't be compatible with this. – Gilles 'SO- stop being evil' Jan 14 '17 at 15:28