diff options
Diffstat (limited to 'dot/local/bin/latest')
-rwxr-xr-x | dot/local/bin/latest | 36 |
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 |
5 | Usage: $0 [directory] [...] | 5 | Usage: $0 [directory] [...] |
6 | Usage: $0 --help | ||
6 | 7 | ||
7 | Print the filename of the newest file. | 8 | Searches the current directory if none is specified. |
9 | |||
10 | Print one filename: the single newest ordinary file from all (not each) | ||
11 | of the specified directories. | ||
12 | |||
13 | If there are no ordinary files, there is no output. | ||
14 | |||
15 | Symbolic links are not listed. | ||
8 | 16 | ||
9 | Searches the directories specified on the command line, | ||
10 | or else the current directory if none specified. | ||
11 | EOF | 17 | EOF |
12 | } | 18 | } |
13 | 19 | ||
14 | case $# in | 20 | case $# 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 | ;; | ||
17 | esac | 28 | esac |
18 | 29 | ||
19 | extract() | 30 | drop_first_word() |
31 | { | ||
32 | sed -ne 's/^[^ ]* //p' | ||
33 | } | ||
34 | |||
35 | extract_newest() | ||
36 | { | ||
37 | sort -z -n -k1,1 -r | head -z -n 1 | xargs -r -0 printf '%s\n' | ||
38 | } | ||
39 | |||
40 | find_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 | ||
24 | find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "%C@ %h/%f\0" \) | extract | 46 | find_simple_files "$@" | extract_newest | drop_first_word |
25 | 47 | ||