# convert json log entries into an array of nu log entries export def `from json-lines` [] { lines | each {|it| try { $it | from json } catch { {msg: $it} }} } export def `follow json-lines` [] { lines | each {|it| try { $it | from json } catch { {msg: $it} } | table --expand | print} | ignore } export def `follow nuon-lines` [] { lines | each {|it| try { $it | from nuon } catch { {msg: $it} } | table --expand | print} | ignore } def --wrapped with-flag [...flag] { if ($in | is-empty) { [] } else { [...$flag $in] } } def --wrapped with-switch [...flag] { if ($in) { [...$flag] } else { [] } } def --wrapped with-name [...name] { if not $in or ($in | is-empty) { [] } else { [...$name]} } # returns the word count of the given file export def wc [ --bytes (-c) # print the byte counts --lines (-l) # count lines instead of words --chars (-m) # print the character counts --max-line-length (-L) # print the maximum display length --words (-w) # print the word counts ...files ] { let c = $bytes | with-switch -c let l = $lines | with-switch -l let m = $chars | with-switch -m let L = $max_line_length | with-switch -L let w = $words | with-switch -w ( ^wc ...([$c $l $m $L $w] | flatten) ...$files | detect columns --no-headers | rename ...([ ($bytes | with-name "bytes") ($lines | with-name "lines") ($chars | with-name "chars") ($max_line_length | with-name "max_line_length") ($words | with-name "words") file ] | flatten ) ) } export def --wrapped df [...$args] { if (["--help", "--version"] | any {|it| $it in $args }) { ^df ...$args } else { ^df ...$args | detect columns --guess } } export def --env dotenv [file=".env"] { if not ($file | path exists) { err make { msg: $"env file ($file) not found "} } ( open $file | lines | each { parse "{key}={value}" | first | { $in.key: $in.value} } | reduce --fold {} {|it, acc| $acc | merge $it } | load-env $in ) }