|
bsleep - Breakable Sleep
========================
bsleep is a sleep that breaks as soon as you press 'b'.
It makes clever use of the -t (timeout) and -n (read n bytes) parameters
of the bash built-in: read.
bsleep can be used to quickly test something and chain a quick undo
command right after you initial command.
example usage:
echo "do something"; bsleep; echo "quickly undo"
The other day I was tinkering with an iptables ruleset and needed exactly
that. So quickly hacked it quick'n'dirty (originally as a one-liner).
The Bash-Shellfunction:
function bsleep () {
local c=1;
local INPUT;
while [ ! "$INPUT" == "b" ]; do
printf "$c "; # comment out if you prefer silent
c=$(($c+1));
read -s -n1 -t1 INPUT;
done;
printf "\n";
}
z
z
Z
.--. Z Z
/ _(c\ .-. __
| / / '-; \'-'` `\______
\_\/'/ __/ ) / ) | \--,
| \`""`__-/ .'--/ /--------\ \
\\` ///-\/ / /---;-. '-'
jgs (________\ \
'-'
|