When measuring elapsed times, instead of executing date(1) to get the current time, use $SECONDS:<p><pre><code> SECONDS
Each time this parameter is referenced, the
number of seconds since shell invocation
is returned. If a value is assigned
to SECONDS, the value returned upon
subsequent references is the number of
seconds since the assignment plus the
value assigned. If SECONDS is unset, it
loses its special properties, even if it is
subsequently reset.
</code></pre>
Like so:<p><pre><code> throttle() {
local -i limit
((limit = SECONDS + $1))
while read line; do
if ((limit < SECONDS)); then
((limit = SECONDS + $1))
echo "$line"
fi
done
}
</code></pre>
Try it like so:<p><pre><code> $ yes | throttle 2
</code></pre>
Of course, that's a bad example in that yes(1) will go as fast as you let it and it always outputs the same thing. In the case of yes(1) the better thing to do would be to sleep between reads, but yes(1) is a special case.
The term debouncing is also used in an analogous manner for electromechanical switches and is probably the origin of the term. These switches literally 'bounce' off the contact during the first few milliseconds after the circuit is closed, rapidly opening and closing the circuit. Debouncing attempts to filter out these rapid, unwanted changes by e.g. adding a capacitor in parallel.
This seems more like a throttle rather than a debounce:<p><a href="https://css-tricks.com/debouncing-throttling-explained-examples/" rel="nofollow">https://css-tricks.com/debouncing-throttling-explained-examp...</a>
Good script.<p>I have this touchpoint problem too. Since I hate those red eraser nubs anyways, I actually disable them entirely at the xinput level. This breaks the physical right mouse button. (because Linux, ofc) but fortunately the touchpad driver replaces it.<p>Better overall experience without any chance of pausing as the driver bounces back.