From: Siraaj Khandkar Date: Mon, 30 Jul 2018 14:15:19 +0000 (-0400) Subject: Add energy X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=75b08dad7fa9e103945fa514fabb7de509e9101a;p=khatus.git Add energy --- diff --git a/bin/khatus_loop b/bin/khatus_loop index cec2359..edefb98 100755 --- a/bin/khatus_loop +++ b/bin/khatus_loop @@ -2,6 +2,18 @@ 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}' } @@ -283,6 +295,13 @@ consume() { -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() @@ -458,6 +477,7 @@ consume() { } 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() @@ -477,6 +497,18 @@ consume() { 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"] @@ -746,6 +778,7 @@ main() { 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 \