Skip to content

Instantly share code, notes, and snippets.

@xerp
Forked from mikesmullin/watch.sh
Last active October 12, 2015 08:10
Show Gist options
  • Select an option

  • Save xerp/be149568dc900bf4ddbb to your computer and use it in GitHub Desktop.

Select an option

Save xerp/be149568dc900bf4ddbb to your computer and use it in GitHub Desktop.

Revisions

  1. xerp revised this gist Oct 12, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions watch.sh
    Original file line number Diff line number Diff line change
    @@ -29,8 +29,10 @@ update_sha() {
    update_sha
    previous_sha=$sha
    build() {
    echo -en "--> building...\n\n"
    $cmd
    if [[ $cmd != "NONE" ]] ; then
    echo -en "--> building...\n\n"
    $cmd
    fi
    }

    compare() {
  2. xerp revised this gist Oct 12, 2015. 1 changed file with 17 additions and 6 deletions.
    23 changes: 17 additions & 6 deletions watch.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env bash
    # script: watch
    # author: Mike Smullin <[email protected]>
    # authors: Mike Smullin <mike@smullindesign.com>, Santiago de Pedro <santiago.pedro23@gmail.com>
    # license: GPLv3
    # description:
    # watches the given path for changes
    @@ -10,23 +10,33 @@
    #

    path=$1

    if [[ ! $path ]] ; then
    path=`pwd`
    fi

    shift
    cmd=$*

    if [[ ! $cmd ]] ; then
    cmd="NONE"
    fi

    sha=0
    update_sha() {
    sha=`ls -lR --time-style=full-iso $path | sha1sum`
    }
    update_sha
    previous_sha=$sha
    build() {
    echo -en " building...\n\n"
    echo -en "--> building...\n\n"
    $cmd
    echo -en "\n--> resumed watching."
    }

    compare() {
    update_sha
    if [[ $sha != $previous_sha ]] ; then
    echo -n "change detected,"
    echo -en "\n--> change DETECTED\n"
    build
    previous_sha=$sha
    else
    @@ -37,8 +47,9 @@ trap build SIGINT
    trap exit SIGQUIT

    echo -e "--> Press Ctrl+C to force build, Ctrl+\\ to exit."
    echo -en "--> watching \"$path\"."
    echo -e "--> command [$cmd]"
    echo -e "--> watching [$path]"
    while true; do
    compare
    sleep 1
    done
    done
  3. @mikesmullin mikesmullin revised this gist Aug 31, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion watch.sh
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ shift
    cmd=$*
    sha=0
    update_sha() {
    sha=`ls -lR $path | sha1sum`
    sha=`ls -lR --time-style=full-iso $path | sha1sum`
    }
    update_sha
    previous_sha=$sha
  4. @mikesmullin mikesmullin created this gist Aug 31, 2013.
    44 changes: 44 additions & 0 deletions watch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/usr/bin/env bash
    # script: watch
    # author: Mike Smullin <[email protected]>
    # license: GPLv3
    # description:
    # watches the given path for changes
    # and executes a given command when changes occur
    # usage:
    # watch <path> <cmd...>
    #

    path=$1
    shift
    cmd=$*
    sha=0
    update_sha() {
    sha=`ls -lR $path | sha1sum`
    }
    update_sha
    previous_sha=$sha
    build() {
    echo -en " building...\n\n"
    $cmd
    echo -en "\n--> resumed watching."
    }
    compare() {
    update_sha
    if [[ $sha != $previous_sha ]] ; then
    echo -n "change detected,"
    build
    previous_sha=$sha
    else
    echo -n .
    fi
    }
    trap build SIGINT
    trap exit SIGQUIT

    echo -e "--> Press Ctrl+C to force build, Ctrl+\\ to exit."
    echo -en "--> watching \"$path\"."
    while true; do
    compare
    sleep 1
    done