-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbt
executable file
·94 lines (85 loc) · 2.6 KB
/
bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
# shellcheck disable=1090,2154
systemctl is-active bluetooth >/dev/null || exit 1
. "${XDG_CACHE_HOME:-$HOME/.cache}/wal/colors.sh"
blockcolor=$color11
txtcolor=$color8
btinfo=$(for dev in $(bluetoothctl devices | cut -d ' ' -f2); do
bluetoothctl info "$dev"
done)
connected_devices=$(echo "$btinfo" | grep -B9 'Connected: yes' |
grep Device | cut -d ' ' -f2)
connected_devices_info=$(for dev in $connected_devices; do echo "$btinfo" |
sed -n "/$dev/,/^Device/p"; done)
if [ -d "/usr/share/icons/HighContrast" ]; then
notif_icon="/usr/share/icons/HighContrast/256x256/status/bluetooth-active.png"
elif [ -d "/usr/share/icons/Adwaita" ]; then
notif_icon="/usr/share/icons/Adwaita/96x96/devices/bluetooth-symbolic.symbolic.png"
else
# TODO: curl a default bluetooth icon.
true
fi
case $BLOCK_BUTTON in
1) # Left Click
bt-select
;;
2) # Middle Click
if systemctl is-active bluetooth >/dev/null; then
sudo systemctl stop bluetooth &
notify-send -i $notif_icon "Stopping Bluetooth service"
else
sudo systemctl restart bluetooth &
notify-send -i $notif_icon "Starting Bluetooth service"
fi
;;
3) # Right Click
notify-send -i $notif_icon "Bluetooth Info" "$connected_devices_info"
;;
4) # Scroll Up
;;
5) # Scroll Down
;;
esac
if [ ! "$connected_devices" ]; then
out="X"
else
# TODO: Provide identifiable information per connected device
# - First letter of device name?
for device in $connected_devices; do
current_device_info=$(echo "$btinfo" | sed -n "/$device/,/^Device/$!p")
case "$(echo "$current_device_info" | grep Icon | cut -d ' ' -f2)" in
"audio-card")
out="${out}"
;;
"audio-headphones" | "audio-headset")
out="${out}"
;;
"input-gaming")
out="${out}"
;;
"phone")
out="${out}"
;;
*)
out="${out}X"
;;
esac
# Only display battery level if feature available.
grep -q 'Experimental.=.true' /etc/bluetooth/main.conf ||
pgrep -f 'bluetoothd -E' &&
battery_level=$(echo "$current_device_info" | grep 'Percentage' | cut -d ' ' -f4)
# NOTE: Account for bug when Battery level doesn't show up when HFP/HSP
# devices are missing.
# [ "$battery_level" ] || { bluetoothctl disconnect "$device"; sleep 3;
# bluetoothctl connect "$device"; }
out="$out$(echo "$battery_level" | sed -e 's/)/%)/g' -e 's/(/ (/g') "
done
fi
out=$(echo "$out" | sed 's/ $//')
icon=
printf "<b><span foreground='%s' background='%s'></span>" \
"$blockcolor" "$color0"
printf "<span foreground='%s' background='%s'> %s </span>" \
"$txtcolor" "$blockcolor" "$icon $out"
printf "<span foreground='%s' background='%s'></span></b>\n" \
"$color0" "$blockcolor"