Giter Site home page Giter Site logo

debounce.sh's Introduction

๐ŸŽฑ debounce.sh

A generic debounce for Bash.

gif of script running on command line

Debouncing is the process of taking multiple sequential events of the same type and grouping them together as one. By treating a group of events as one event, you can handle them all at once instead of handling each event individually.

Debounce is often used in front-end design for things like autosaving a form that a user is typing in - but only after they have finished typing for some time (all keypress events are grouped together and treated as one).

Debouncing requires an event generating program and an action to run when the event generating program has not generated an event for a certain time interval.

Usage

Pass three parameters to debounce.sh:

  1. DEBOUNCE_PROGRAM: a program that you want to run continuously but that periodically returns successfully when an event occurs (ex a file watcher like inotifywait that returns successfully when a file is changed).
  2. DEBOUNCE_INTERVAL_SECONDS: a time interval in seconds to wait when the debounce program returns successfully
  3. DEBOUNCE_ACTION: a program that runs when the DEBOUNCE_PROGRAM has not generated new events for DEBOUNCE_INTERVAL_SECONDS seconds.

Generic usage:

./debounce.sh ./debounce_program.sh debounce_interval_seconds ./debounce_action.sh

Watch standard input and print "Ran action" whenever text has been submitted to standard input but not submitted again for 5 seconds

./debounce.sh "read" 5 "echo 'Ran action'"

Watch my technical journal file and run an action whenever it has been saved but not saved again for 10 seconds

./debounce.sh ./inotifywait-debounce.sh 10 ./action.sh

Tests

Tests are written with Bash Automated Testing Systems 2018 (bats-core).

Run tests in test/:

bats test.bats

debounce.sh's People

Contributors

merklebros avatar

Stargazers

Daniel Kuruc avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.