Skip to content

Instantly share code, notes, and snippets.

@raspberrypisig
Forked from knadh/zsh-elapsed-time.md
Created June 24, 2020 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raspberrypisig/49da5945c9fc3269fbf85ffca43c3f61 to your computer and use it in GitHub Desktop.
Save raspberrypisig/49da5945c9fc3269fbf85ffca43c3f61 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