Created
May 23, 2025 23:16
-
-
Save clipperhouse/5e8c726bc951d30ce1879a2436645dfa to your computer and use it in GitHub Desktop.
zshrc to show timing of last command
This file contains hidden or 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
# High-precision timer using epoch nanoseconds | |
function preexec() { | |
TIMER=$(gdate +%s%3N 2>/dev/null || date +%s%3N) | |
LAST_COMMAND="$1" | |
} | |
function precmd() { | |
if [[ -n "$TIMER" && -n "$LAST_COMMAND" ]]; then | |
NOW=$(gdate +%s%3N 2>/dev/null || date +%s%3N) | |
DURATION=$((NOW - TIMER)) | |
if (( DURATION > 1 )); then | |
echo "\033[2m⏱️ ${DURATION} ms\033[0m" | |
fi | |
fi | |
unset LAST_COMMAND | |
} |
Author
clipperhouse
commented
May 23, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment