From 1225086f3e1f520b5a35d2798ad29427cbee6e14 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 19 Nov 2023 17:52:25 +0100 Subject: bashrc: show run time of commands --- bashrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 -- cgit v1.2.3