• Operand
  • hole: deep pi.

gram: build

> ./config/nushell/day.nu

Lenses
(coming soon!)


def "clock sync" [] { nsh ntp sudo ntpdate time.nist.gov }
def clock [] { let c = cloq; $"($c.day)_($c.cloc)_z($c.zone)" }
def cloq [] {
  run-external date '-Is' |
  parse '{day}T{cloc}-{zone}' |
  update cells -c [ cloc zone ] { $in | str replace -a -r ':' '-' } |
  into record }
def cloc [] { (cloq).cloc | str replace -a ':' '-' }

def dura [...command: string] { let cl = (clock); echo ($cl); time ...$command; echo; echo ($cl); clock; }

# parse durations, as in:
# 04:44:44 -> 04hr 44min 44sec
def "dura parse" [phrase: string] {
  (($phrase | str replace ':' 'hr ' | str replace ':' 'min ') + 'sec') | into duration
}

def day [label?: string] {
  if ($label | is-empty) { date now } else { get $label } |
  format date "%Y-%m-%d" }

def mon [label?: string] {
  if ($label | is-empty) { date now } else { get $label } |
  format date "%Y-%m" }

def year [] { cal --full-year 2024 --week-start monday; }

def "days gram" [
  place?: path,
  label?: string,
  --plan (-p),
] {
  let grammar = days group
  let label = if ($label | is-empty) { $place | path basename } else { $label }
  let plan = $plan or ($place | is-empty)

  if ($place | is-empty) { print $grammar
  } else { $grammar | each {|r|
    send --plan=($plan) (
      $r | get nodes | get name) (
      [ $place $"($r | get day).($label)" ] | path join | path expand)
  } }
}