summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2023-11-19 17:52:25 +0100
committerReiner Herrmann <reiner@reiner-h.de>2023-11-19 17:52:25 +0100
commit1225086f3e1f520b5a35d2798ad29427cbee6e14 (patch)
tree5790ff3867ab518ec2142de2684f699deab80310
parent3b0fcfa346f8114f9c82700cdac47d30d2964bc8 (diff)
bashrc: show run time of commands
-rw-r--r--bashrc12
1 files changed, 12 insertions, 0 deletions
diff --git a/bashrc b/bashrc
index 5c58c9e..b587b0a 100644
--- a/bashrc
+++ b/bashrc
@@ -47,6 +47,11 @@ case "$TERM" in
;;
esac
+before_command() {
+ command_timer=${command_timer:-$(date +%s)}
+}
+trap 'before_command' DEBUG
+
# prompt
__prompt_command() {
local exit_code=$?
@@ -87,6 +92,13 @@ __prompt_command() {
PS1+=" <$red_b$exit_code$reset>"
fi
+ # runtime
+ local command_runtime=$(($(date +%s) - $command_timer))
+ unset command_timer
+ if [ $command_runtime -gt 0 ]; then
+ PS1+=" (${command_runtime}s)"
+ fi
+
PS1+=" $red\$$reset > "
}
PROMPT_COMMAND=__prompt_command