#!/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
