aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/sketchybar/bar-config/plugins/bluetooth.sh
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/modules/sketchybar/bar-config/plugins/bluetooth.sh')
-rwxr-xr-xusers/ryan/modules/sketchybar/bar-config/plugins/bluetooth.sh37
1 files changed, 37 insertions, 0 deletions
diff --git a/users/ryan/modules/sketchybar/bar-config/plugins/bluetooth.sh b/users/ryan/modules/sketchybar/bar-config/plugins/bluetooth.sh
new file mode 100755
index 0000000..80185c0
--- /dev/null
+++ b/users/ryan/modules/sketchybar/bar-config/plugins/bluetooth.sh
@@ -0,0 +1,37 @@
1#!/usr/bin/env bash
2source "$CONFIG_DIR/colors.sh"
3source "$CONFIG_DIR/icons.sh"
4
5CACHE="/tmp/sketchybar_${NAME}.txt"
6case "$SENDER" in
7 mouse.entered)
8 [ -f "$CACHE" ] && sketchybar --set "$NAME.details" label="$(cat "$CACHE")"
9 sketchybar --set "$NAME" popup.drawing=on; exit 0 ;;
10 mouse.exited)
11 sketchybar --set "$NAME" popup.drawing=off; exit 0 ;;
12esac
13
14if ! command -v blueutil >/dev/null 2>&1; then
15 sketchybar --set "$NAME" label="$BT_OFF" label.color=$TEXT_DIM
16 printf '%s' "blueutil not installed" > "$CACHE"
17 exit 0
18fi
19
20if [ "$1" = "toggle" ]; then
21 if [ "$(blueutil -p)" = "1" ]; then blueutil -p 0; else blueutil -p 1; fi
22fi
23
24if [ "$(blueutil -p)" = "1" ]; then
25 NAMES="$(blueutil --connected 2>/dev/null | grep -o 'name: "[^"]*"' | sed 's/name: "//; s/"$//' | paste -sd , - | sed 's/,/, /g')"
26 COUNT="$(blueutil --connected 2>/dev/null | grep -c 'name:')"
27 if [ "$COUNT" -gt 0 ]; then
28 sketchybar --set "$NAME" label="$BT_CONNECTED" label.color=$TEXT
29 printf '%s' "Bluetooth on · $COUNT connected: $NAMES" > "$CACHE"
30 else
31 sketchybar --set "$NAME" label="$BT_ON" label.color=$TEXT
32 printf '%s' "Bluetooth on · no devices connected" > "$CACHE"
33 fi
34else
35 sketchybar --set "$NAME" label="$BT_OFF" label.color=$TEXT_DIM
36 printf '%s' "Bluetooth off" > "$CACHE"
37fi