+ int charge_now, current_now, m, h;
+ float timeleft;
+ char path[PATH_MAX], state[12];
+
+ if (esnprintf(path, sizeof(path),
+ "/sys/class/power_supply/%s/status",
+ bat) < 0) {
+ return NULL;
+ }
+ if (pscanf(path, "%12s", state) != 1) {
+ return NULL;
+ }
+
+ if (pick(bat, CHARGE_NOW, ENERGY_NOW, path, sizeof (path)) == NULL ||
+ pscanf(path, "%d", &charge_now) < 0) {
+ return NULL;
+ }
+
+ if (!strcmp(state, "Discharging")) {
+ if (pick(bat, CURRENT_NOW, POWER_NOW, path, sizeof (path)) == NULL ||
+ pscanf(path, "%d", ¤t_now) < 0) {
+ return NULL;
+ }
+
+ timeleft = (float)charge_now / (float)current_now;
+ h = timeleft;
+ m = (timeleft - (float)h) * 60;
+
+ return bprintf("%dh %dm", h, m);
+ }
+
+ return "";