Files
dotfiles/Scripts/.local/scripts/status/bluetooth-status
Aryadev Chavali 0d374a5f82 awk refactor of my scripts
awk is OP man - so easy to use and does a bunch of stuff all at once
without having to rely on multiple pipes.  It comes with essentially
every distribution so you'll always have access to it.
2025-11-04 16:37:44 +00:00

26 lines
532 B
Bash
Executable File

#!/usr/bin/env sh
devices=$(bluetoothctl devices Connected | awk '{print $2}')
if [ -z "$devices" ]
then
echo ''
else
sep=''
printf ' '
for mac in $devices
do
name=$(bluetoothctl info $mac | awk -F ': ' '/Alias/ { print $2 }')
battery=$(bluetoothctl info $mac | awk -F '[()]' '/Battery Percentage/ { print $2 }')
printf "$sep<$name"
if [ "$battery" ]
then
printf " $battery%%"
fi
printf ">"
sep=" "
done
printf "\n"
fi