2024-03-15 13:51:15 +01:00
|
|
|
#!/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
|
2024-03-20 01:30:27 +01:00
|
|
|
def notify [message: string, urgent: bool] {
|
|
|
|
match $urgent {
|
|
|
|
true => (notify-send "Status" $message -u critical)
|
|
|
|
false => (notify-send "Status" $message)
|
|
|
|
}
|
2024-03-15 13:51:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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 [] {
|
2024-03-20 01:30:27 +01:00
|
|
|
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
|
2024-03-15 13:51:15 +01:00
|
|
|
}
|