The bang history mechanism allow to specify a backward relative command, like !-2 to relaunch the penultimate command. That's fine but if you launch history, you will only have the command serial number, which depending of your history length may be far longer.
So what I would like is a way to define a command extended_history which print
-5 12342 print example
[…]
-2 12345 print foo
-1 12346 print bar
At least on linux there a the tools tac (which prints lines in reverse order) and nl (which numbers lines).
So this should do the trick although without leading -:
extended_history () {
history "$@" | tac | nl | tac
}
If you really want the -
extended_history () {
history "$@" | tac | nl | tac | sed 's/^\( *\)\([0-9]\)/\1-\2/'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With