From db8ff593eef1ce8abdb0b84406d79df6714f60e4 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 2 Nov 2020 20:18:50 -0500 Subject: [PATCH] Check if upower is on path before calling it --- home/lib/login_functions.sh | 51 ++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/home/lib/login_functions.sh b/home/lib/login_functions.sh index c4a583a..e6c159d 100644 --- a/home/lib/login_functions.sh +++ b/home/lib/login_functions.sh @@ -431,30 +431,33 @@ flat_top_5() { motd_batt() { case "$(uname)" in 'Linux') - upower --dump \ - | awk ' - /^Device:[ \t]+/ { - device["path"] = $2 - next - } - - / battery/ && device["path"] { - device["is_battery"] = 1 - next - } - - / percentage:/ && device["is_battery"] { - device["battery_percentage"] = $2 - sub("%$", "", device["battery_percentage"]) - next - } - - /^$/ { - if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice") - print device["battery_percentage"], 100, "batt" - delete device - } - ' + if which upower > /dev/null + then + upower --dump \ + | awk ' + /^Device:[ \t]+/ { + device["path"] = $2 + next + } + + / battery/ && device["path"] { + device["is_battery"] = 1 + next + } + + / percentage:/ && device["is_battery"] { + device["battery_percentage"] = $2 + sub("%$", "", device["battery_percentage"]) + next + } + + /^$/ { + if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice") + print device["battery_percentage"], 100, "batt" + delete device + } + ' + fi ;; esac } -- 2.20.1