add latest.nim

This commit is contained in:
Rasmus Moorats 2023-09-30 15:41:59 +03:00
parent 5dccc81116
commit f3d30c81c5
Signed by: xx
GPG key ID: FE14255A6AE7241C
2 changed files with 24 additions and 0 deletions

View file

@ -8,6 +8,7 @@ srcDir = "src"
bin = @["b64d",
"b64e",
"glog",
"latest",
"bcat"]
binDir = "bin"

23
src/latest.nim Normal file
View file

@ -0,0 +1,23 @@
import std/[os, posix, posix_utils]
proc `<`(t1, t2: Time): bool {.borrow.}
var
params = commandLineParams()
latest: (string, Time)
if params.len < 1:
params = @[getCurrentDir()]
for dir in params:
for file in walkDir dir:
let
s = stat file.path
tim =
when StatHasNanoseconds: s.st_mtim.tv_sec
else: s.st_mtime
if latest[1] < tim:
latest = (file.path, tim)
stdout.write latest[0]
stdout.flushFile