Skip to content

Instantly share code, notes, and snippets.

@icculus
Forked from DavidLudwig/SDLBugCount.sh
Last active August 29, 2015 14:22
Show Gist options
  • Save icculus/f343008f69c2126dd51c to your computer and use it in GitHub Desktop.
Save icculus/f343008f69c2126dd51c to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# SDL 2.0.4 Bug-"Count" Checker for Mac OS X or KDE
# Version 1.6
#
# Requirements:
# - any one of the following command-line notification tools:
# - Growl and growlnotify, for Mac OS X, available at http://growl.info
# - kdialog, for KDE
# - notify-send, for generic Linux notifications
# - curl
#
# Tech notes:
# - temporary files are placed directly in /tmp. According to the interwebs,
# OS X deletes these files every few days, if left unused... probably. To
# clear these files manually, run:
# rm "/tmp/SDLBugCount*"
#
# History:
# 1.0: first release, ha ha ha!
# 1.1: better messages, ha ha ha!
# 1.1.1: code cleanups, ha ha ha!
# 1.2: fixed number parsing bugs, ha ha ha!
# 1.3: one, one notification window, ha ha ha!
# 1.4: click to show info, ha ha ha!
# 1.5: KDE support, ha ha ha! (Thanks @thothonegan !)
# 1.6: notify-send support, ha ha ha! (Thanks @icculus !)
#
ICON_FILE="/tmp/SDLBugCountIcon.png"
ICON_URL="http://icons.iconarchive.com/icons/pino/sesame-street/32/The-Count-icon.png"
INFO_URL="https://bugzilla.libsdl.org/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=WAITING&bug_status=RESPONDED&bug_status=ASSIGNED&bug_status=REOPENED&keywords=target-2.0.4&keywords_type=allwords&list_id=12321&query_format=advanced"
REFRESH_IN_SECONDS=600
MESSAGE_FORMAT="%s bugs left in SDL 2.0.4, ha ha ha!"
NOTIFICATION_ID=$(basename "$0")
do_notify () {
if type -P growlnotify > /dev/null; then
growlnotify -m "$1" --image "$ICON_FILE" -d "$NOTIFICATION_ID" --url "$INFO_URL" -s
elif type -P notify-send > /dev/null; then
# Notifications don't come up on Ubuntu 14.04 unless they are critical, wtf?
notify-send -u "critical" -i "$ICON_FILE" "SDLBugCount" "$1" 2>/dev/null
elif type -P kdialog > /dev/null; then
kdialog --passivepopup "$1" 5 --icon "$ICON_FILE" --title "SDLBugCount"
fi
}
# Detect notify program
if type -P growlnotify > /dev/null; then
:
elif type -P notify-send > /dev/null; then
:
elif type -P kdialog > /dev/null; then
:
else
echo "Please install a notify program, such as:"
echo "- growlnotify: for Mac OS X; can be found at http://growl.info/downloads"
echo "- kdialog: part of KDE"
echo "- notify-send: generic Linux notifier"
exit 1
fi
# Detect curl
if ! type -P curl > /dev/null; then
echo "Please install 'curl'"
exit 1
fi
# Download icon
if [ ! -f "$ICON_FILE" ]; then
echo "Setting up 1 icon, ha ha ha!"
curl "$ICON_URL" -o "$ICON_FILE"
fi
# Check for status, display as appropriate, rinse-and-repeat
COUNT=""
while true; do
NEW_COUNT=`curl -s "$INFO_URL" | grep "bugs found" | head -1 | perl -pne 's/^.*[^\d](\d+) bugs found.*/$1/'`
if [ "$NEW_COUNT" != "" ] && [ "$NEW_COUNT" != "$COUNT" ]; then
COUNT="$NEW_COUNT"
MESSAGE=`printf "$MESSAGE_FORMAT" "$COUNT"`
echo "$MESSAGE"
do_notify "$MESSAGE"
fi
sleep "$REFRESH_IN_SECONDS"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment