Last active
August 29, 2015 13:56
-
-
Save lyoshenka/9160727 to your computer and use it in GitHub Desktop.
My simple timer to alert me when the chicken's ready to take out of the oven.
This file contains 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 | |
FILENAME=$(basename "$0") | |
PID=$(pgrep -o "$FILENAME") | |
if [ "$1" = "-k" ]; then | |
MIN=$(ps -o start= -o cmd= -p "$PID" | cut -d' ' -f4) | |
if [[ "$MIN" =~ ^-?[0-9]+$ ]]; then | |
echo "Killing timer" | |
kill -9 "$PID" | |
else | |
echo "No timer" | |
fi | |
elif [[ "$1" =~ ^-?[0-9]+$ ]]; then | |
echo "Chicken in $1 minutes" | |
sleep "$1m" && boxcar.php "chicken" && notify-send --urgency=low -i face-cool "chicken" & | |
elif [ -n "$1" ]; then | |
echo "Usage: $0 [-k | MINUTES]" | |
else | |
INFO=$(ps -o start= -o cmd= -p "$PID") | |
START=$(echo "$INFO" | cut -d' ' -f1) | |
MIN=$(echo "$INFO" | cut -d' ' -f4) | |
NOW=$(date +%s) | |
THEN=$(date +%s --date="$START") | |
if [ -n "$MIN" ]; then | |
LEFT=$(( (THEN + MIN*60 - NOW) / 60 + 1 )) | |
if [[ $LEFT < 1 ]]; then LEFT='less than one'; fi | |
echo "$LEFT minutes left" | |
else | |
echo "No timer" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment