summaryrefslogtreecommitdiff
path: root/dot/local/bin/latest
diff options
context:
space:
mode:
Diffstat (limited to 'dot/local/bin/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