Skip to content

Instantly share code, notes, and snippets.

@DrPep
Forked from knadh/zsh-elapsed-time.md
Created July 25, 2021 17:05
Show Gist options
  • Save DrPep/6c2981b20e8b87bb6e3cd5d4427a1dbf to your computer and use it in GitHub Desktop.
Save DrPep/6c2981b20e8b87bb6e3cd5d4427a1dbf 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