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.

Revisions

  1. @knadh knadh revised this gist Jul 14, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions zsh-elapsed-time.md
    Original file line number Diff line number Diff line change
    @@ -7,12 +7,12 @@ Append this to your ~/.zshrc file.

    ```shell
    function preexec() {
    timer=$(($(date +%s%N)/1000000))
    timer=$(($(date +%s%0N)/1000000))
    }

    function precmd() {
    if [ $timer ]; then
    now=$(($(date +%s%N)/1000000))
    now=$(($(date +%s%0N)/1000000))
    elapsed=$(($now-$timer))

    export RPROMPT="%F{cyan}${elapsed}ms %{$reset_color%}"
  2. @knadh knadh created this gist Dec 7, 2016.
    24 changes: 24 additions & 0 deletions zsh-elapsed-time.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    ## Elapsed and execution time display for commands in ZSH

    <img src="http://i.imgur.com/EFGhkzQ.png">


    Append this to your ~/.zshrc file.

    ```shell
    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](https://coderwall.com/p/kmchbw/zsh-display-commands-runtime-in-prompt]).