Skip to main content

Timed Terminal Commands

Lesser Known Trick. Add this to ~/.zshrc or anything equivalent.

preexec() {
timer=$(gdate +%s.%N)
}

precmd() {
if [ -n "$timer" ]; then
now=$(gdate +%s.%N)
elapsed=$(echo "$now - $timer" | bc)
timer_show=$(printf "%.2f" $elapsed)
echo "⏱ ${timer_show}s"
unset timer
fi
}