1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 08:09:03 -08:00

accelerate decently with ls sorting and ignore more stuff

This commit is contained in:
Connor Olding 2021-10-08 14:31:20 -07:00
parent f0fedca16f
commit cdd044cb0b

View file

@ -15,12 +15,31 @@ decently() ( ### @-
### has its timestamp updated. symlinks are followed.
### `.git` subdirectories are skipped over.
### the timestamps of subdirectories are ignored.
local arg= dir= latest= prev= ts= fails= succs=0
finder() { find "$dir" -type f "$@" '!' -path '*/.git/*' -print -quit; }
[ -n "$1" ] || { printf '%s: missing directory argument\n' decently >&2; return 1; }
local arg= dir= latest= prev= ts= fails= succs=0
finder() {
find "$dir" -type f "$@" \
'!' \
'(' -path '*/.git/*' \
-or -path '*/__pycache__/*' \
-or -path '*/[Dd]esktop.ini' \
-or -path '*/Thumbs.db' \
-or -path '*/.DS_Store' \
')' \
-exec ls -t1 '{}' + \
2>/dev/null \
| while read -r f; do
printf '%s\n' "$f"
break
done
}
for arg; do
dir="$(readlink -f -- "$arg")" || continue
[ -d "$dir" ] || { printf '%s: not a directory: %s\n' decently "$dir" >&2; continue; }
prev=
latest="$(finder)" || continue
while [ -n "$latest" ]; do
@ -28,12 +47,14 @@ decently() ( ### @-
latest="$(finder -newer "$latest")" || break
done
[ -e "$prev" ] || { printf '%s: no valid files found: %s\n' decently "$dir" >&2; continue; }
ts="$(date -u '+%s' -r "$prev")"
dir="${dir%/}/" # ensure dir has a trailing slash
printf '%s\t%s\n' "$ts" "${arg%/}/${prev#$dir}"
touch -c -r "$prev" "$dir" || continue
: $(( succs+=1 ))
done
fails=$(( $# - succs ))
[ $fails -le 255 ] || fails=255
return $fails