[bluetooth_info.pl]: print battery percentage only if defined

Also add keyboard & mouse icons
This commit is contained in:
2025-02-19 16:21:39 +00:00
parent f8d0f7c180
commit b3b0f9b663

View File

@ -9,12 +9,15 @@ my $output = `bluetoothctl info` or die("disconnected\n");
my $mac_address = ($output =~ /^Device\s+(\S+)/) ? "$1" : die("disconnected\n"); my $mac_address = ($output =~ /^Device\s+(\S+)/) ? "$1" : die("disconnected\n");
my $device_name = ($output =~ /Name:\s+(.*)/) ? "$1" : "unknown"; my $device_name = ($output =~ /Name:\s+(.*)/) ? "$1" : "unknown";
my $icon = ($output =~ /Icon:\s+(.*)/) ? "$1" : ""; my $icon = ($output =~ /Icon:\s+(.*)/) ? "$1" : "";
my $battery_percentage = ($output =~ /Battery Percentage:\s+\S+\s\(([0-9]+)\)/) ? "$1" : "?"; my $battery_percentage = ($output =~ /Battery Percentage:\s+\S+\s\(([0-9]+)\)/) ? "$1" : undef;
my %icons = ( my %icons = (
"audio-headphones" => "", "audio-headphones" => "",
"audio-headset" => "" "audio-headset" => "",
"input-keyboard" => "",
"input-mouse" => "󰍽"
); );
printf("$icons{$icon} ") if exists $icons{$icon}; printf("$icons{$icon} ") if exists $icons{$icon};
printf("$device_name $battery_percentage%%"); printf("$device_name");
printf(" $battery_percentage%%") if defined $battery_percentage;