Elapsed and execution time display for commands in ZSH
Append this to your ~/.zshrc file.
function preexec() {
timer=$(($(date +%s%0N)/1000000))
}
function precmd() {
if [ $timer ]; then
now=$(($(date +%s%0N)/1000000))
elapsed=$(($now-$timer))
export RPROMPT="%F{cyan}${elapsed}ms %{$reset_color%}"
unset timer
fi
}
Remixed from @adri's snippet.
bad math expression: operator expected at 'N/1000000'
This happens on MAc because OSX doesn't support milliseconds. You should either remove
%N
and only get precision close to seconds, or install coreutils as explained here: https://apple.stackexchange.com/questions/135742/time-in-milliseconds-since-epoch-in-the-terminalAlternatively you can just use 'time [your command here]` to see how long it takes