diff options
Diffstat (limited to 'dot/local/bin')
-rwxr-xr-x | dot/local/bin/latest | 25 |
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 | ||
2 | usage() | ||
3 | { | ||
4 | cat <<EOF | ||
5 | Usage: $0 [directory] [...] | ||
6 | |||
7 | Print the filename of the newest file. | ||
8 | |||
9 | Searches the directories specified on the command line, | ||
10 | or else the current directory if none specified. | ||
11 | EOF | ||
12 | } | ||
13 | |||
14 | case $# in | ||
15 | 0) set -- . ;; | ||
16 | 1) if [ "$1" = --usage ]; then usage; exit 0; fi ;; | ||
17 | esac | ||
18 | |||
19 | extract() | ||
20 | { | ||
21 | sort -z -n -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | cut -d' ' -f2 | ||
22 | } | ||
23 | |||
24 | find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "%C@ %h/%f\0" \) | extract | ||
25 | |||