Skip to content

Instantly share code, notes, and snippets.

@lauriro
Last active December 23, 2015 18:19
Show Gist options
  • Select an option

  • Save lauriro/6675170 to your computer and use it in GitHub Desktop.

Select an option

Save lauriro/6675170 to your computer and use it in GitHub Desktop.

Revisions

  1. lauriro revised this gist Sep 24, 2013. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions time_to_run.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Add to .bashrc and try it out
    # Add to .bashrc or .zshrc and try it out
    # $ sleep 5
    # -- Runs: 5 seconds
    # -- Runs 5 seconds

    time_to_words() {
    local mod num="$1" out=""
    @@ -15,14 +15,14 @@ time_to_words() {
    echo $out
    }

    prompt_command() {
    precmd() {
    CUR=`date +%s`
    RUN=`expr $CUR - ${PS_TIME-$CUR}`

    test $RUN -gt 4 && echo "-- Runs: `time_to_words $RUN`" >&2
    test $RUN -gt 4 && echo "-- Runs `time_to_words $RUN`" >&2

    # Capture time
    trap 'PS_TIME=`date +%s`; trap DEBUG' DEBUG
    }

    PROMPT_COMMAND=prompt_command
    PROMPT_COMMAND=precmd # for bash, zsh uses precmd directly
  2. lauriro created this gist Sep 23, 2013.
    28 changes: 28 additions & 0 deletions time_to_run.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # Add to .bashrc and try it out
    # $ sleep 5
    # -- Runs: 5 seconds

    time_to_words() {
    local mod num="$1" out=""
    set -- 60 second 60 minute 24 hour 7 day 4 week 12 month

    while test $num -gt 0; do
    mod=`expr $num % $1`
    num=`expr $num / $1`
    test $mod -gt 0 && out="$mod $2`test $mod -gt 1 && echo s` $out"
    shift 2
    done
    echo $out
    }

    prompt_command() {
    CUR=`date +%s`
    RUN=`expr $CUR - ${PS_TIME-$CUR}`

    test $RUN -gt 4 && echo "-- Runs: `time_to_words $RUN`" >&2

    # Capture time
    trap 'PS_TIME=`date +%s`; trap DEBUG' DEBUG
    }

    PROMPT_COMMAND=prompt_command