Init
This commit is contained in:
commit
4d0fac3707
23
flatpak-updater.nu
Executable file
23
flatpak-updater.nu
Executable file
|
@ -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
|
||||
}
|
66
status-notification.nu
Executable file
66
status-notification.nu
Executable file
|
@ -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)
|
||||
}
|
48
timer.nu
Executable file
48
timer.nu
Executable file
|
@ -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"
|
||||
}
|
||||
|
Loading…
Reference in a new issue