Skip to content

Instantly share code, notes, and snippets.

@oneilsh
Created July 31, 2016 19:13
Show Gist options
  • Save oneilsh/76092e3642aa94fe832e4c47979d5045 to your computer and use it in GitHub Desktop.
Save oneilsh/76092e3642aa94fe832e4c47979d5045 to your computer and use it in GitHub Desktop.
Add a timer for the last command to your bash prompt
# 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