summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-09-14 02:39:00 -0400
committerAndrew Cady <d@jerkface.net>2021-09-14 02:39:00 -0400
commitdc3122f0da01a20361e73c77cac7d0f58f859ceb (patch)
tree1bebfabdf2e6466a2530bc9e227db77c02973401
parent1d070275ef256f3b15894f83ef7d01f487448163 (diff)
new command: latest
-rwxr-xr-xdot/local/bin/latest25
1 files changed, 25 insertions, 0 deletions
diff --git a/dot/local/bin/latest b/dot/local/bin/latest
new file mode 100755
index 0000000..e475c1b
--- /dev/null
+++ b/dot/local/bin/latest
@@ -0,0 +1,25 @@
1#!/bin/sh
2usage()
3{
4 cat <<EOF
5Usage: $0 [directory] [...]
6
7Print the filename of the newest file.
8
9Searches the directories specified on the command line,
10or else the current directory if none specified.
11EOF
12}
13
14case $# in
15 0) set -- . ;;
16 1) if [ "$1" = --usage ]; then usage; exit 0; fi ;;
17esac
18
19extract()
20{
21 sort -z -n -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | cut -d' ' -f2
22}
23
24find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "%C@ %h/%f\0" \) | extract
25