fish: add functions to get the {new,old}est file in a directory tree
Alan Pearce alan@alanpearce.eu
Wed, 15 May 2024 17:29:53 +0200
2 files changed, 24 insertions(+), 0 deletions(-)
A user/settings/fish/functions/newest.fish
@@ -0,0 +1,12 @@+function newest + if test (count $argv) -eq 0 + echo "Need at least one path" + return 1 + end + for arg in $argv + fd --hidden --print0 --max-depth 1 . $arg | + bfs -files0-from - \( -name .git -prune \) -o \( -printf '%TY%Tm%Td%TR %TF %h/%f\0' \) | + sort --zero-terminated --reverse --key 1n,1 | head --zero-terminated --lines 1 | + cut --delimiter ' ' --fields 2,3 + end +end
A user/settings/fish/functions/oldest.fish
@@ -0,0 +1,12 @@+function oldest + if test (count $argv) -eq 0 + echo "Need at least one path" + return 1 + end + for arg in $argv + fd --hidden --print0 --max-depth 1 . $arg | + bfs -files0-from - \( -name .git -prune \) -o \( -printf '%TY%Tm%Td%TR %TF %h/%f\0' \) | + sort --zero-terminated --key 1n,1 | head --zero-terminated --lines 1 | + cut --delimiter ' ' --fields 2,3 + end +end