doti3/bar/src/volume.php
2021-03-03 21:31:06 +01:00

38 lines
821 B
PHP
Executable file

#!/usr/bin/env php
<?php
require __DIR__.'/base/block.php';
$volume = trim(shell_exec('/usr/bin/amixer get Master'));
if (!empty($volume)) {
preg_match('/\[([0-9%]+)\]/', $volume, $match);
if ($match[1]) {
$v = (int) str_replace('%', '', $match[1]);
$fullText = ' '.$match[1].' ';
if ($v === 0) {
$fullText.= emoji(0xf026);
} elseif ($v < 50) {
$fullText.= emoji(0xf027);
} else {
$fullText.= emoji(0xf028);
}
echo block(
'volume',
[
'full_text' => $fullText,
'color' => color('music'),
'markup' => 'pango',
'separator' => false,
'separator_block_width' => 0,
]
);
die(0);
}
}