summary refs log tree commit diff stats
path: root/user/settings/fish
diff options
context:
space:
mode:
authorAlan Pearce2024-05-20 20:29:46 +0200
committerAlan Pearce2024-05-20 20:29:46 +0200
commita2d6adfa523a32e1f8c184602eec555365bc02c9 (patch)
tree1c7ed34137ecef2cb2c9a37017749a40ed4e003a /user/settings/fish
parentd2db2799c625d163bbe54500854fc73ec350e574 (diff)
downloadnixfiles-a2d6adfa523a32e1f8c184602eec555365bc02c9.tar.lz
nixfiles-a2d6adfa523a32e1f8c184602eec555365bc02c9.tar.zst
nixfiles-a2d6adfa523a32e1f8c184602eec555365bc02c9.zip
fish: fix newest/oldest
before:
 - errors if arg was not a directory
 - hours and minutes were incorrectly separated, making sort
 inaccurate
 - `newest` would show the oldest file as reverse is handled per-key
Diffstat (limited to 'user/settings/fish')
-rw-r--r--user/settings/fish/functions/newest.fish10
-rw-r--r--user/settings/fish/functions/oldest.fish10
2 files changed, 12 insertions, 8 deletions
diff --git a/user/settings/fish/functions/newest.fish b/user/settings/fish/functions/newest.fish
index 73e26dcc..3f2fa66f 100644
--- a/user/settings/fish/functions/newest.fish
+++ b/user/settings/fish/functions/newest.fish
@@ -4,9 +4,11 @@ function newest
         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\n' \) |
-            sort --reverse --key 1n,1 | head --lines 1 |
-            cut -d ' ' -f 2,3
+        if test -d $arg
+            fd --hidden --print0 --max-depth 1 . $arg |
+                bfs -files0-from - \( -name .git -prune \) -o \( -printf '%TY%Tm%Td%TH%TM %TF %h/%f\n' \) |
+                sort --key 1nr,1 | head --lines 1 |
+                cut -d ' ' -f 2,3
+        end
     end
 end
diff --git a/user/settings/fish/functions/oldest.fish b/user/settings/fish/functions/oldest.fish
index 66aad720..140d74cc 100644
--- a/user/settings/fish/functions/oldest.fish
+++ b/user/settings/fish/functions/oldest.fish
@@ -4,9 +4,11 @@ function oldest
         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\n' \) |
-            sort --key 1n,1 | head --lines 1 |
-            cut -d ' ' -f 2,3
+        if test -d $arg
+            fd --hidden --print0 --max-depth 1 . $arg |
+                bfs -files0-from - \( -name .git -prune \) -o \( -printf '%TY%Tm%Td%TH%TM %TF %h/%f\n' \) |
+                sort --key 1n,1 | head --lines 1 |
+                cut -d ' ' -f 2,3
+        end
     end
 end