Skip to content

Commit e7efa0a

Browse files
committed
Added "vsleep" which verbosely counts down the time left
Motivation here is I keep find myself doing: sleep 15m && mplayer alarm.ogg and such. If I want to see how much time is left, I'm SOL. With this, I can see how much time is left. Probably I should hunt down a decent stopwatch/kitchen timer program instead, but I've yet to find one that works well for me.
1 parent 133750c commit e7efa0a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

vsleep

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# substitute for the traditional "sleep" command
4+
# This will print the time remaining on stdout, so if you have to interrupt it you can restart at approximately the same place.
5+
6+
7+
case "$1" in
8+
--help)
9+
cat <<EOF
10+
Usage: sleep NUMBER[SUFFIX]
11+
Pause for NUMBER seconds. SUFFIX may be 'm' for minutes, 'h' for hours, 'd' for days, or 's' for seconds (the default)
12+
Giving more than one argument is an error. Giving no arguments is an error.
13+
--help: print help and exit
14+
--version: print version and exit
15+
EOF
16+
exit
17+
;;
18+
--version)
19+
echo "vsleep v.1 https://github.com/jgilmore/Cruft"
20+
exit
21+
esac
22+
23+
if [ "$1" == "" -o "$2" != "" ]; then
24+
echo "vsleep: too many or too few arguments" 1>&2
25+
exit 255
26+
fi
27+
SUFFIX=${1#${1%?}}
28+
if [ "$SUFFIX" != "s" -a "$SUFFIX" != 'h' -a "$SUFFIX" != 'm' -a "$SUFFIX" != 'd' ]; then
29+
SUFFIX='s'
30+
fi
31+
NUMBER=${1%%$SUFFIX}
32+
#echo n=$NUMBER
33+
#echo s=$SUFFIX
34+
35+
#Test for a valid number
36+
if [ "$NUMBER" -ge 0 ] 2>/dev/null
37+
then
38+
echo number >/dev/null
39+
else
40+
echo "vsleep: Not a number" 1>&2
41+
exit 254
42+
fi
43+
44+
while [ "$NUMBER" -gt "0" ]; do
45+
echo -en $NUMBER " \r"
46+
sleep 1$SUFFIX
47+
NUMBER=$(( $NUMBER - 1 ))
48+
done
49+
50+
#Final echo puts the prompt on the next line, and properly shows "0" as the final number
51+
echo "0 "

0 commit comments

Comments
 (0)