Created
July 31, 2016 19:13
-
-
Save oneilsh/76092e3642aa94fe832e4c47979d5045 to your computer and use it in GitHub Desktop.
Add a timer for the last command to your bash prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# timer prompt, add to ~/.bashrc (tested in bash only thus far) | |
function timer_start { | |
timer=${timer:-$SECONDS} | |
} | |
function timer_stop { | |
i=$(($SECONDS - $timer)) | |
((sec=i%60, i/=60, min=i%60, hrs=i/60)) | |
timer_show=$(printf "%d:%02d:%02d" $hrs $min $sec) | |
unset timer | |
} | |
trap 'timer_start' DEBUG | |
if [ "$PROMPT_COMMAND" == "" ]; then | |
PROMPT_COMMAND="timer_stop" | |
else | |
PROMPT_COMMAND="$PROMPT_COMMAND; timer_stop" | |
fi | |
PS1='[last: ${timer_show}s] '$PS1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment