diff --git a/src/bin/status-notification b/src/bin/status-notification new file mode 100755 index 0000000..8d86075 --- /dev/null +++ b/src/bin/status-notification @@ -0,0 +1,68 @@ +#!/usr/bin/env nu + +# (ls).name | each {|item| (cat $"($item)/capacity") } | lines +# open uevent | lines | parse "{key}={value}" | transpose -r +# let batteries = ( (ls /sys/class/power_supply).name | each {|item| open $"($item)/uevent" } | each {|item| $item | lines | parse "{key}={value}" | transpose -r }) + +let dateString = ^date +let discordianDate = ^ddate + +def get_batteries [] { + let power_supplies = ( + (ls /sys/class/power_supply).name + | each {|item| + open $"($item)/uevent" + } + | each {|item| + $item | lines | parse "{key}={value}" + }) + + let batteries = $power_supplies | each {|| + $in | dfr into-df | dfr get key | dfr contains POWER_SUPPLY_CAPACITY | dfr into-nu | get key | any {|| $in == true } + } | into record | items {|k,v| + if $v == true { + ($power_supplies | get ($k | into int) | transpose -r) + } + } | each {|| $in} + + $batteries | each {|i| + [ $i.POWER_SUPPLY_MANUFACTURER $i.POWER_SUPPLY_MODEL_NAME $i.POWER_SUPPLY_CAPACITY ] + | each {|j| + $j | first + } + } | each {|str| + $str | str join " " + } | each {|str| + $str | str replace -r '$' '%' + } | str join "\n" +} + +# Documentation for notify +def notify [message: string, urgent: bool] { + match $urgent { + true => (notify-send "Status" $message -u critical) + false => (notify-send "Status" $message) + } +} + +def calendar [hours: int] { + let events = do { qcal -cron (60 * $hours) } | complete + if $events.stdout == "" { + $"No events in the next ($hours) hours." + } else { + $"Events in the next ($hours) hours:\n($events.stdout)" + } +} + +# Documentation for construct_string +def main [] { + let calendar_status = calendar 2 + let urgent = not ($calendar_status | str starts-with "No events") + notify ( + [ $dateString + $discordianDate + $calendar_status + (get_batteries) + ] | str join "\n\n" + ) $urgent +}