summaryrefslogtreecommitdiff
path: root/mac/.config/sketchybar.yabai/plugins/github.sh
diff options
context:
space:
mode:
authorTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-08-23 12:42:37 +0900
committerTheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com>2025-08-23 12:42:37 +0900
commit07d294425a98ee5d1e22d03e2b24ae2c76e487c0 (patch)
treea6818f0d64438c5fdb88b00a35d944f80c056213 /mac/.config/sketchybar.yabai/plugins/github.sh
parent6fc28cdb3529ca8ee864cb5c41674cb0a4af72a1 (diff)
updates
Diffstat (limited to 'mac/.config/sketchybar.yabai/plugins/github.sh')
-rwxr-xr-xmac/.config/sketchybar.yabai/plugins/github.sh108
1 files changed, 108 insertions, 0 deletions
diff --git a/mac/.config/sketchybar.yabai/plugins/github.sh b/mac/.config/sketchybar.yabai/plugins/github.sh
new file mode 100755
index 0000000..bf09991
--- /dev/null
+++ b/mac/.config/sketchybar.yabai/plugins/github.sh
@@ -0,0 +1,108 @@
+#!/bin/bash
+
+update() {
+ source "$CONFIG_DIR/colors.sh"
+ source "$CONFIG_DIR/icons.sh"
+
+ NOTIFICATIONS="$(gh api notifications)"
+ COUNT="$(echo "$NOTIFICATIONS" | jq 'length')"
+ args=()
+ if [ "$NOTIFICATIONS" = "[]" ]; then
+ args+=(--set $NAME icon=$BELL label="0")
+ else
+ args+=(--set $NAME icon=$BELL_DOT label="$COUNT")
+ fi
+
+ PREV_COUNT=$(sketchybar --query github.bell | jq -r .label.value)
+ # For sound to play around with:
+ # afplay /System/Library/Sounds/Morse.aiff
+
+ args+=(--remove '/github.notification\.*/')
+
+ COUNTER=0
+ COLOR=$BLUE
+ args+=(--set github.bell icon.color=$COLOR)
+
+ while read -r repo url type title; do
+ COUNTER=$((COUNTER + 1))
+ IMPORTANT="$(echo "$title" | egrep -i "(deprecat|break|broke)")"
+ COLOR=$BLUE
+ PADDING=0
+
+ if [ "${repo}" = "" ] && [ "${title}" = "" ]; then
+ repo="Note"
+ title="No new notifications"
+ fi
+ case "${type}" in
+ "'Issue'")
+ COLOR=$GREEN
+ ICON=$GIT_ISSUE
+ URL="$(gh api "$(echo "${url}" | sed -e "s/^'//" -e "s/'$//")" | jq .html_url)"
+ ;;
+ "'Discussion'")
+ COLOR=$WHITE
+ ICON=$GIT_DISCUSSION
+ URL="https://www.github.com/notifications"
+ ;;
+ "'PullRequest'")
+ COLOR=$MAGENTA
+ ICON=$GIT_PULL_REQUEST
+ URL="$(gh api "$(echo "${url}" | sed -e "s/^'//" -e "s/'$//")" | jq .html_url)"
+ ;;
+ "'Commit'")
+ COLOR=$WHITE
+ ICON=$GIT_COMMIT
+ URL="$(gh api "$(echo "${url}" | sed -e "s/^'//" -e "s/'$//")" | jq .html_url)"
+ ;;
+ esac
+
+ if [ "$IMPORTANT" != "" ]; then
+ COLOR=$RED
+ ICON=􀁞
+ args+=(--set github.bell icon.color=$COLOR)
+ fi
+
+ notification=(
+ label="$(echo "$title" | sed -e "s/^'//" -e "s/'$//")"
+ icon="$ICON $(echo "$repo" | sed -e "s/^'//" -e "s/'$//"):"
+ icon.padding_left="$PADDING"
+ label.padding_right="$PADDING"
+ icon.color=$COLOR
+ position=popup.github.bell
+ icon.background.color=$COLOR
+ drawing=on
+ click_script="open \"$URL\"; sketchybar --set github.bell popup.drawing=off; sleep 5; sketchybar --trigger github.update"
+ )
+
+ args+=(--clone github.notification.$COUNTER github.template
+ --set github.notification.$COUNTER "${notification[@]}")
+ done <<<"$(echo "$NOTIFICATIONS" | jq -r '.[] | [.repository.name, .subject.latest_comment_url, .subject.type, .subject.title] | @sh')"
+
+ sketchybar -m "${args[@]}" >/dev/null
+
+ if [ $COUNT -gt $PREV_COUNT ] 2>/dev/null || [ "$SENDER" = "forced" ]; then
+ sketchybar --animate tanh 15 --set github.bell label.y_offset=5 label.y_offset=0
+ fi
+}
+
+popup() {
+ sketchybar --set $NAME popup.drawing=$1
+}
+
+case "$SENDER" in
+"routine" | "forced" | "github.update")
+ update
+ ;;
+"system_woke")
+ sleep 10 && update # Wait for network to connect
+ ;;
+"mouse.entered")
+ popup on
+ ;;
+"mouse.exited" | "mouse.exited.global")
+ popup off
+ ;;
+"mouse.clicked")
+ popup toggle
+ ;;
+esac