mirror of
https://github.com/tomru/hlwm-config.git
synced 2026-03-03 06:27:20 +01:00
40 lines
1.1 KiB
JavaScript
Executable File
40 lines
1.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
const linuxBattery = require('linux-battery');
|
|
|
|
async function run() {
|
|
try {
|
|
const batteries = await linuxBattery();
|
|
batteries.forEach(battery => {
|
|
if (battery.powerSupply === 'no') {
|
|
return '';
|
|
}
|
|
|
|
const color = battery.warningLevel !== 'none' ? '#ff0000' : '#eee8d5';
|
|
let stateSymbol = battery.state === 'charging' ? '↑' : '↓';
|
|
switch (battery.state) {
|
|
case 'charging':
|
|
stateSymbol = '↑';
|
|
break;
|
|
case 'fully-charged':
|
|
stateSymbol = 'F';
|
|
break;
|
|
case 'discharging':
|
|
stateSymbol = '↓';
|
|
break;
|
|
default:
|
|
|
|
}
|
|
const timeLeft = battery.timeToFull || battery.timeToEmpty || '';
|
|
|
|
const text = `%{F${color}}${battery.percentage} ${stateSymbol} ${timeLeft}%{F-}`;
|
|
process.stdout.write(text);
|
|
});
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
run();
|