summary refs log tree commit diff stats
path: root/user/settings/fish/functions
diff options
context:
space:
mode:
authorAlan Pearce2024-05-15 17:29:53 +0200
committerAlan Pearce2024-05-15 17:29:53 +0200
commitc8be1dd4c46d231dc2c7bd0dea51e382bba9f7a1 (patch)
treefd4a509b9c3bc7e731a917b537e74769b1f28944 /user/settings/fish/functions
parent791e22191a5d762ec9d958ddad57bfa1533d52c3 (diff)
downloadnixfiles-c8be1dd4c46d231dc2c7bd0dea51e382bba9f7a1.tar.lz
nixfiles-c8be1dd4c46d231dc2c7bd0dea51e382bba9f7a1.tar.zst
nixfiles-c8be1dd4c46d231dc2c7bd0dea51e382bba9f7a1.zip
fish: add functions to get the {new,old}est file in a directory tree
Diffstat (limited to 'user/settings/fish/functions')
-rw-r--r--user/settings/fish/functions/newest.fish12
-rw-r--r--user/settings/fish/functions/oldest.fish12
2 files changed, 24 insertions, 0 deletions
diff --git a/user/settings/fish/functions/newest.fish b/user/settings/fish/functions/newest.fish
new file mode 100644
index 00000000..645e0d9f
--- /dev/null
+++ b/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
diff --git a/user/settings/fish/functions/oldest.fish b/user/settings/fish/functions/oldest.fish
new file mode 100644
index 00000000..26d53c0f
--- /dev/null
+++ b/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