Skip to content

Instantly share code, notes, and snippets.

@lyoshenka
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyoshenka/9160727 to your computer and use it in GitHub Desktop.
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.
#!/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