Skip to content

Instantly share code, notes, and snippets.

@riazXrazor
Forked from knadh/zsh-elapsed-time.md
Created July 13, 2022 16:20
Show Gist options
  • Save riazXrazor/9341049dd3a30c5f82f18ae37fc8d609 to your computer and use it in GitHub Desktop.
Save riazXrazor/9341049dd3a30c5f82f18ae37fc8d609 to your computer and use it in GitHub Desktop.
Elapsed and execution time for commands in ZSH

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment