• Operand
  • no leg, a'sea.

gram:build

> ./config/nushell/day.nu

Lenses
(coming soon!)


def "clock sync" [] { nsh ntp sudo ntpdate time.nist.gov }
def clock [] { run-external date '-Is'; }

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) { run-external date "-I"
  } else { get $label | format date "%Y-%m-%d" } }

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)
  } }
}