nu-scripts/timer.nu

49 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-03-15 13:51:15 +01:00
#!/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"
}