summaryrefslogtreecommitdiff
path: root/dot/local/bin/latest
blob: ef95cfe5625c12c09094a2e81a9f68563303b57e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
usage()
{
    cat <<EOF
Usage: $0 [directory] [...]

Print the filename of the newest file.

Searches the directories specified on the command line,
or else the current directory if none specified.
EOF
}

case $# in
    0) set -- . ;;
    1) if [ "$1" = --usage ]; then usage; exit 0; fi ;;
esac

extract()
{
    sort -z -n -k1,1 -r | head -z -n 1 | xargs -0 printf '%s\n' | perl -pe 's/.*? //'
}

find "$@" -maxdepth 1 -name '.*' -o \( -type f -printf "%C@ %h/%f\0" \) | extract