commit 4d0fac37078e0f4668a0d7879b6e23f14f3307c5 Author: Marty Sluijtman Date: Fri Mar 15 13:51:15 2024 +0100 Init diff --git a/flatpak-updater.nu b/flatpak-updater.nu new file mode 100755 index 0000000..e433f8d --- /dev/null +++ b/flatpak-updater.nu @@ -0,0 +1,23 @@ +#!/usr/bin/env nu + +# Documentation for notify +def notify [message: string, prefix?: string] { + notify-send $"Flatpak updater ($prefix)" $message +} + +def update_flatpaks [] { + notify "Starting unattended flatpak update..." + let flatpak_status = do { flatpak update -y } | complete + if $flatpak_status != 0 { + if $flatpak_status.stderr != "" { + notify $flatpak_status.stderr "stderr" + } + } else { + notify "Unattended update complete.\nConsider restarting presently running flatpaks." + } +} + +# Documentation for main +def main [] { + update_flatpaks +} \ No newline at end of file diff --git a/status-notification.nu b/status-notification.nu new file mode 100755 index 0000000..3116052 --- /dev/null +++ b/status-notification.nu @@ -0,0 +1,66 @@ +#!/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] { + 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 construct_string [] { + [ $dateString + $discordianDate + (calendar 2) + (get_batteries) + ] | str join "\n\n" +} + +# Documentation for main +def main [] { + notify (construct_string) +} diff --git a/timer.nu b/timer.nu new file mode 100755 index 0000000..7a55fae --- /dev/null +++ b/timer.nu @@ -0,0 +1,48 @@ +#!/usr/bin/env nu +let timeStamps = $"($env.XDG_DATA_HOME)/stamps.csv" + +# Documentation for main +def main [] { + "this is a pipeline function that does nothing on it's own" +} + +def "main diff" [] { + let fileContent = open $timeStamps + let latestStart = ($fileContent | where event == Start | last).date | into datetime + let latestStop = ($fileContent | where event == Stop | last).date | into datetime + + let comparewith = if $latestStart > $latestStop { + date now + } else { + $latestStop + } + $comparewith - $latestStart +} + +# Documentation for "main view" +def "main view" [] { + echo $timeStamps + open $timeStamps +} + +# Documentation for "main init" +def "main init" [] { + echo "date,event\n" | save --append $timeStamps +} + +# Documentation for add_stamp +def add_stamp [event: string # Event name + ] { + echo $"(date now | debug),($event)\n" | save --append $timeStamps +} + +# Add "Start" event to timestamps +def "main start" [ ] { + add_stamp "Start" +} + +# Add "Stop" event to timestamps +def "main stop" [] { + add_stamp "Stop" +} +