#!/usr/bin/php
<?php

require __DIR__.'/base/block.php';

$acpi = shell_exec('acpi');

if (!preg_match('`Discharging`', $acpi)) {
    preg_match('`([0-9]+%)`', $acpi, $values);

    if (!empty($values)) {
        $charging = (int) $values[1];

        if ($charging === 100) {
            return;
        }

        if ($charging < 20) {
            $foreground = '#333';
            $background = color('critical');
        } elseif ($charging < 50) {
            $foreground = color('info');
            $background = color('warning');
        } else {
            $foreground = '#333';
            $background = color('normal');
        }

        $charging .= '% '.emoji(0xf0aa);

        $text = span(' '.$charging.' ', $foreground, $background);

        $block = block(
            'acpi',
            [
                'full_text' => $text,
                'color' => $color,
                'separator' => false,
                'separator_block_width' => 0,
            ]
        );
    } else {
        $block = block(
            'acpi',
            [
                'full_text' => '??? '.emoji(0xf0aa),
                'color' => color('info'),
                'separator' => false,
                'separator_block_width' => 0,
            ]
        );
    }
} else {
    preg_match('`([0-9]+%), ([0-9]+:[0-9]+)`', $acpi, $values);

    if ($values[0] < 20) {
        $foreground = '#333';
        $background = color('critical');
    } elseif ($values[0] < 50) {
        $foreground = color('info');
        $background = color('warning');
    } else {
        $foreground = '#333';
        $background = color('normal');
    }

    $charging = $values[1];
    $times = str_replace(':', 'h', $values[2]);
    $text = span(' '.implode(' ', [$charging, $times, emoji(0xf0ab)]).' ', $foreground, $background);

    $block = block(
        'acpi',
        [
            'full_text' => $text,
            'color' => $color,
            'separator' => false,
            'separator_block_width' => 0,
        ]
    );
}

echo $block;
Embed
<div%key%id="gist-5c87a9d93b60d-9fe3a5ee26e2cc88e63b8b6093e452e689878513" class="gist-container"></div>
<script src="https://gist.deblan.org/en/embedjs/5c87a9d93b60d" async></script>