Last active
January 27, 2016 08:44
-
-
Save mitio/adc940a5d6f0cd97d3e1 to your computer and use it in GitHub Desktop.
A very simple bash timer to let you know when a certain amount of time has elapsed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
duration="$1" | |
if [ -z "$duration" ]; then | |
echo "Usage: $0 <duration> where duration is a number in seconds, or a number with an m or a h suffix." >&2 | |
echo "Examples:" >&2 | |
echo "$0 10" >&2 | |
echo "$0 15m" >&2 | |
exit 1 | |
fi | |
numeric_duration=`echo $duration | sed 's/[^0-9]//g'` | |
if echo $duration | grep -q m; then | |
duration_in_seconds=$(( 60 * $numeric_duration )) | |
elif echo $duration | grep -q h; then | |
duration_in_seconds=$(( 3600 * $numeric_duration )) | |
else | |
duration_in_seconds=$numeric_duration | |
fi | |
echo "Waiting for $duration ($duration_in_seconds seconds)..." | |
sleep $duration_in_seconds | |
echo 'Time is up!' | |
if which -s terminal-notifier; then | |
terminal-notifier -title 'Time is up!' -message 'The timer you set has just completed.' | |
fi | |
if which -s say; then | |
say 'Time is up! I repeat - time is up!' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment