Skip to content

Instantly share code, notes, and snippets.

@gilgamezh
Forked from knadh/zsh-elapsed-time.md
Created May 16, 2017 19:33
Show Gist options
  • Save gilgamezh/fd27f24d7e71844b918b965cccd8b957 to your computer and use it in GitHub Desktop.
Save gilgamezh/fd27f24d7e71844b918b965cccd8b957 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%N)/1000000))
}

function precmd() {
  if [ $timer ]; then
    now=$(($(date +%s%N)/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