Created
June 15, 2020 20:05
-
-
Save invidian/47ae993133271be23acb472d9f25c0b1 to your computer and use it in GitHub Desktop.
xfce4-genmon-plugin script for GitHub notifications
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 | |
NOTIFICATIONS_COUNT=0 | |
NOTIFICATIONS_URL=https://github.com/notifications | |
ICONS_DIR=~/.cache/githubstatus-indicator | |
ICONS_SIZE=32 | |
TEXT="No new notifications." | |
GITHUB_USERNAME=$(yq -r '.hosts["github.com"].user' ~/.config/gh/config.yml) | |
GITHUB_TOKEN=$(yq -r '.hosts["github.com"].oauth_token' ~/.config/gh/config.yml) | |
ICON='<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> | |
<path fill-rule="evenodd" clip-rule="evenodd" d="M16 0C7.16 0 0 7.16 0 16C0 23.08 4.58 29.06 10.94 31.18C11.74 31.32 12.04 30.84 12.04 30.42C12.04 30.04 12.02 28.78 12.02 27.44C8 28.18 6.96 26.46 6.64 25.56C6.46 25.1 5.68 23.68 5 23.3C4.44 23 3.64 22.26 4.98 22.24C6.24 22.22 7.14 23.4 7.44 23.88C8.88 26.3 11.18 25.62 12.1 25.2C12.24 24.16 12.66 23.46 13.12 23.06C9.56 22.66 5.84 21.28 5.84 15.16C5.84 13.42 6.46 11.98 7.48 10.86C7.32 10.46 6.76 8.82 7.64 6.62C7.64 6.62 8.98 6.2 12.04 8.26C13.32 7.9 14.68 7.72 16.04 7.72C17.4 7.72 18.76 7.9 20.04 8.26C23.1 6.18 24.44 6.62 24.44 6.62C25.32 8.82 24.76 10.46 24.6 10.86C25.62 11.98 26.24 13.4 26.24 15.16C26.24 21.3 22.5 22.66 18.94 23.06C19.52 23.56 20.02 24.52 20.02 26.02C20.02 28.16 20 29.88 20 30.42C20 30.84 20.3 31.34 21.1 31.18C27.42 29.06 32 23.06 32 16C32 7.16 24.84 0 16 0V0Z" fill="#FFFFFF"/> | |
</svg>' | |
ICON_PENDING='<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"> | |
<path d="M0 16C0 7.16 7.16 0 16 0C24.84 0 32 7.16 32 16C32 16.3358 31.9896 16.6693 31.9692 17H26.1121C26.1957 16.44 26.24 15.8283 26.24 15.16C26.24 13.4 25.62 11.98 24.6 10.86C24.76 10.46 25.32 8.82 24.44 6.62C24.44 6.62 23.1 6.18 20.04 8.26C18.76 7.9 17.4 7.72 16.04 7.72C14.68 7.72 13.32 7.9 12.04 8.26C8.98 6.2 7.64 6.62 7.64 6.62C6.76 8.82 7.32 10.46 7.48 10.86C6.46 11.98 5.84 13.42 5.84 15.16C5.84 20.6387 8.82119 22.3187 12 22.8976V25.2442C11.0224 25.6632 8.83035 26.2166 7.44 23.88C7.14 23.4 6.24 22.22 4.98 22.24C3.64 22.26 4.44 23 5 23.3C5.68 23.68 6.46 25.1 6.64 25.56C6.95947 26.4585 7.99655 28.1743 12 27.4437V30.6814C11.8951 31.0116 11.5751 31.2911 10.94 31.18C4.58 29.06 0 23.08 0 16Z" fill="#FFFFFF"/> | |
<circle cx="26" cy="26" r="5" fill="#FF0000"/> | |
</svg>' | |
function svg() { | |
if [ ! -d $ICONS_DIR ]; then | |
mkdir -p $ICONS_DIR | |
fi | |
OUTPUT=$ICONS_DIR/$(basename $1) | |
if [ -f $OUTPUT ]; then | |
echo $OUTPUT | |
return 0 | |
fi | |
INPUT=$ICONS_DIR/$(basename $1).orig | |
if [ ! -f $INPUT ]; then | |
echo $2 > $INPUT | |
fi | |
if ! which rsvg-convert >/dev/null; then | |
echo "" | |
return 1 | |
fi | |
rsvg-convert -w $ICONS_SIZE -h $ICONS_SIZE $INPUT > $OUTPUT | |
if [ $? -ne 0 ]; then | |
return 1 | |
fi | |
echo $OUTPUT | |
return 0 | |
} | |
NOTIFICATIONS=$(curl -s -u ${GITHUB_USERNAME}:${GITHUB_TOKEN} https://api.github.com/notifications | jq '.[] | select(.unread) | "\(.subject.type): \(.repository.full_name): \(.subject.title)"') | |
if [[ ! -z "${NOTIFICATIONS}" ]]; then | |
NOTIFICATIONS_COUNT=1 | |
TEXT=$NOTIFICATIONS | |
fi | |
if [[ $NOTIFICATIONS_COUNT -gt 0 ]]; then | |
echo "<img>$(svg "icon-pending.svg" "${ICON_PENDING}")</img>" | |
else | |
echo "<img>$(svg "icon.svg" "${ICON}")</img>" | |
fi | |
echo -e "<tool>$TEXT</tool><click>xdg-open ${NOTIFICATIONS_URL}</click>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment