-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBTBL
More file actions
27 lines (22 loc) · 733 Bytes
/
BTBL
File metadata and controls
27 lines (22 loc) · 733 Bytes
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
#! /bin/bash
# bluetooth battery level
# 2022-06-28 01:27:46 - fixes
# 2022-08-01 23:12:38 - show emoji
dev=headset_dev_XX_XX_XX_XX_XX_XX # find it via upower -d
test -n "$1" && dev="$1"
getdata=`upower --show-info "/org/freedesktop/UPower/devices/$dev"`
test -n "`echo "$getdata" | grep '(null)'`" && echo "⊝" && exit
level=`echo "$getdata" | awk '/percentage/{print $2}' | sed 's/%//'`
# check if it's a valid number
case "$level" in
''|*[!0-9]*) exit 1;;
esac
# only show emoji for a graphical session
if [ "$TERM" = "dumb" ]; then
if [ "$level" -gt 39 ]; then # adjust to your situation: below 40% is already too low/little for me
echo -n " 🔋"
else
echo -n " 🪫"
fi
fi
echo "${level}%"