I often happen to forget to explicitly prefix executions with the "time" command, ideally I would see in the next shell prompt how much real time the last command took (on every command).
I already scoured through the bash documentation, but couldn't find anything related.
Using Bash Shell's TIMEFORMAT The TIMEFORMAT is a string format that will be printed after the execution of the block code inside the time{} wrapper finishes. The %R specifies to print the elapsed time in seconds with milliseconds precision. Let's test our script: $ ./elapsed_time.sh It took 12.008 seconds.
You could do this:
$ bind '"\C-j": "\C-atime \C-m"'
Or put this in your ~/.inputrc
:
"\C-j": "\C-atime \C-m"
Then when you want to do time sleep 1
you'd type sleep 1
and press Ctrl+J instead of Enter.
I would not recommend swapping the j
and m
in the bind command (or in the .inputrc file). Every time you'd press Enter you'd get time
added which could be pretty annoying and would cause errors when typing a multi-line command.
You could add this to your ~/.bashrc
to make the output of time
more compact:
export TIMEFORMAT='r: %R, u: %U, s: %S'
(similar to my answer here.)
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