Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Forked from mikesmullin/watch.sh
Last active June 8, 2023 15:55
Show Gist options
  • Select an option

  • Save molotovbliss/aee0792414a00757e587333c438b7e4b to your computer and use it in GitHub Desktop.

Select an option

Save molotovbliss/aee0792414a00757e587333c438b7e4b to your computer and use it in GitHub Desktop.

Revisions

  1. molotovbliss revised this gist Mar 18, 2017. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions watchdo.sh
    Original file line number Diff line number Diff line change
    @@ -19,10 +19,9 @@ sha=0
    echo -en "Generating checksum from $path ...\n\n"

    update_sha() {
    # use find + stat for faster recursive files date, size and filename
    # NOTE: If checksum generation is slow try a smaller size directory.
    #sha=`ls -lR --time-style=full-iso $path | sha1sum`
    sha=`find $path -type f -exec stat -c '%y %s %n *' '{}' + | sha1sum`
    sha=`ls -lR --time-style=full-iso $path | sha1sum`
    #sha=`find $path -type f -exec stat -c '%y %s %n *' '{}' + | sha1sum`
    }
    update_sha
    previous_sha=$sha
  2. molotovbliss revised this gist Mar 18, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions watchdo.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/usr/bin/env bash
    # script: watch
    # script: watchdo
    # author: Mike Smullin <mike@smullindesign.com>
    # modified: Jared Blalock <mb@molotovbliss.com>
    # possible use for monitoring .less changes to compile to .css
    @@ -17,24 +17,24 @@ cmd=$*
    sha=0

    echo -en "Generating checksum from $path ...\n\n"
    echo -en "NOTE: If checksum generation is slow try a smaller size directory.\n"

    update_sha() {
    # use find + stat for faster recursive files date, size and filename
    # NOTE: If checksum generation is slow try a smaller size directory.
    #sha=`ls -lR --time-style=full-iso $path | sha1sum`
    sha=`find $path -type f -exec stat -c '%y %s %n *' '{}' + | sha1sum`
    }
    update_sha
    previous_sha=$sha
    build() {
    echo -en "executing: $cmd ...\n\n"
    echo -en "Executing: $cmd ...\n\n"
    $cmd -s
    echo -en "resuming watch: $path "
    echo -en "Resuming watch: $path "
    }
    compare() {
    update_sha
    if [[ $sha != $previous_sha ]] ; then
    echo -n "\nchange detected! "
    echo -n " >> Change detected! << \n\n"
    build
    previous_sha=$sha
    else
  3. molotovbliss revised this gist Mar 18, 2017. 2 changed files with 52 additions and 44 deletions.
    44 changes: 0 additions & 44 deletions watch.sh
    Original file line number Diff line number Diff line change
    @@ -1,44 +0,0 @@
    #!/usr/bin/env bash
    # script: watch
    # author: Mike Smullin <mike@smullindesign.com>
    # 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 --time-style=full-iso $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
    52 changes: 52 additions & 0 deletions watchdo.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/usr/bin/env bash
    # script: watch
    # author: Mike Smullin <mike@smullindesign.com>
    # modified: Jared Blalock <mb@molotovbliss.com>
    # possible use for monitoring .less changes to compile to .css
    # 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

    echo -en "Generating checksum from $path ...\n\n"
    echo -en "NOTE: If checksum generation is slow try a smaller size directory.\n"

    update_sha() {
    # use find + stat for faster recursive files date, size and filename
    #sha=`ls -lR --time-style=full-iso $path | sha1sum`
    sha=`find $path -type f -exec stat -c '%y %s %n *' '{}' + | sha1sum`
    }
    update_sha
    previous_sha=$sha
    build() {
    echo -en "executing: $cmd ...\n\n"
    $cmd -s
    echo -en "resuming watch: $path "
    }
    compare() {
    update_sha
    if [[ $sha != $previous_sha ]] ; then
    echo -n "\nchange detected! "
    build
    previous_sha=$sha
    else
    echo -n .
    fi
    }
    #trap build SIGINT
    #trap exit SIGQUIT

    echo -en " Press Ctrl+C to exit.\n"
    echo -en " ... watching \"$path\"."
    while true; do
    compare
    sleep 1
    done
  4. @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
  5. @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 <mike@smullindesign.com>
    # 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