summaryrefslogtreecommitdiff
path: root/dot/local/bin/latest
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2024-01-19 12:01:49 -0500
committerAndrew Cady <d@jerkface.net>2024-01-19 12:01:49 -0500
commita74be3f9e73d9dd10eee890e673d00bfb44e5cfb (patch)
treed6ac57f28cdd7bf0283234e4730275c0b6afb565 /dot/local/bin/latest
parent66a483f0101ec54bd8db0f7d20ed83fe2f615cf4 (diff)
parentf58705ed7c600a1d394c6949bb7e21cfd29e6260 (diff)
Merge commit 'f587'HEADmaster
Diffstat (limited to 'dot/local/bin/latest')
-rwxr-xr-xdot/local/bin/latest36
1 files changed, 29 insertions, 7 deletions
diff --git a/dot/local/bin/latest b/dot/local/bin/latest
index ef95cfe..12a0a9f 100755
--- a/dot/local/bin/latest
+++ b/dot/local/bin/latest
@@ -3,23 +3,45 @@ usage()
3{ 3{
4 cat <<EOF 4 cat <<EOF
5Usage: $0 [directory] [...] 5Usage: $0 [directory] [...]
6Usage: $0 --help
6 7
7Print the filename of the newest file. 8Searches the current directory if none is specified.
9
10Print one filename: the single newest ordinary file from all (not each)
11of the specified directories.
12
13If there are no ordinary files, there is no output.
14
15Symbolic links are not listed.
8 16
9Searches the directories specified on the command line,
10or else the current directory if none specified.
11EOF 17EOF
12} 18}
13 19
14case $# in 20case $# in
15 0) set -- . ;; 21 0) set -- . ;;
16 1) if [ "$1" = --usage ]; then usage; exit 0; fi ;; 22 1) if [ "$1" = --usage ]
23 then
24 usage
25 exit 0
26 fi
27 ;;
17esac 28esac
18 29
19extract() 30drop_first_word()
31{
32 sed -ne 's/^[^ ]* //p'
33}
34
35extract_newest()
36{
37 sort -z -n -k1,1 -r | head -z -n 1 | xargs -r -0 printf '%s\n'
38}
39
40find_simple_files()
20{ 41{
21 sort -z -n -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | perl -pe 's/.*? //' 42 pattern="%C@ %h/%f\0"
43 find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "$pattern" \)
22} 44}
23 45
24find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "%C@ %h/%f\0" \) | extract 46find_simple_files "$@" | extract_newest | drop_first_word
25 47