set -e
+produce_energy() {
+ upower -e \
+ | grep battery \
+ | xargs upower -i \
+ | awk '
+ /^ +percentage: +/ { percentage=$2 }
+ /^ +state: +/ { state=$2 }
+ END { print(state, percentage) }
+ '
+}
+
+
produce_memory() {
free | awk '$1 == "Mem:" {print $2, $3}'
}
-v opt_mpd_song_max_chars=10 \
-v opt_prefixes_of_net_interfaces_to_show="$prefixes_of_net_interfaces_to_show" \
'
+ /^in:ENERGY/\
+ {
+ split_msg_parts()
+ db["energy_state"] = $1
+ db["energy_percentage"] = $2
+ }
+
/^in:MEMORY/\
{
split_msg_parts()
}
function make_bar( position, bar, sep, i, j) {
+ position[++i] = make_status_energy()
position[++i] = make_status_mem()
position[++i] = make_status_cpu()
position[++i] = make_status_disk()
return bar
}
+ function make_status_energy( state, direction_of_change) {
+ state = db["energy_state"]
+ if (state == "discharging") {
+ direction_of_change = "<"
+ } else if (state == "charging") {
+ direction_of_change = ">"
+ } else {
+ direction_of_change = "="
+ };
+ printf("E%s%s", direction_of_change, db["energy_percentage"])
+ }
+
function make_status_mem( total, used, percent, status) {
total = db["memory_total"]
used = db["memory_used"]
spawn "$cmd_produce_temperature" "$pipe" 'in:TEMPERATURE' 1
spawn "$cmd_produce_fan" "$pipe" 'in:FAN' 1
spawn produce_memory "$pipe" 'in:MEMORY' 1
+ spawn produce_energy "$pipe" 'in:ENERGY' 1
spawn produce_bar_req "$pipe" 'out:BAR' 1
consume \