Ok, there is a way to accomplish your goal. This is just a proof-of-concept, I wouldn't really recommend to do so:
> script --flush /tmp/myscript
Script started, file is /tmp/myscript
> LASTLINE() {
tail -2 /tmp/myscript | head -1 | tr -d '\r'
}
> bind '"^[[15~":"$(LASTLINE)\n"'
> ls -tr1
file1
file2
fileN
> vi [press F5]
The idea: use script
as the tool which remembers in- and output. In the example, it stores all data in file "/tmp/myscript" which in turn can be read to get the last result line.
Since the actual command (vi ...
) is the last line in "myscript", we read the last two lines of that file and use the first one of them. (Additionally, I had to filter the return character via tr
.) Now we bind this command LASTLINE
to F5 (look at In bash, how do I bind a function key to a command? to see in detail how to bind a command to a key).
And from now on, you can press F5 to get the contents of the last output line.
If you do so, remember that you are within a sub-shell (because of script
) which can be left via exit
to get back to your original shell.
Careful: this is more or less playing-with-bash. There are race-conditions and other draw-backs, so
I'd recommend not to use this solution in sensitive environment.