From: Siraaj Khandkar Date: Tue, 3 Nov 2020 01:18:50 +0000 (-0500) Subject: Check if upower is on path before calling it X-Git-Url: https://git.xandkar.net/?p=khome.git;a=commitdiff_plain;h=db8ff593eef1ce8abdb0b84406d79df6714f60e4 Check if upower is on path before calling it --- 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 }