Last active
June 10, 2024 10:32
-
-
Save ormaaj/0ffae6447ba24924e30b66e2618139bc to your computer and use it in GitHub Desktop.
file sorting example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S-- BASH_COMPAT=51 bash -O lastpipe -O extglob -O expand_aliases +O assoc_expand_once +O sourcepath | |
typeset x | |
x=$(pkgconf --var=loadablesdir bash) && | |
[[ ! $BASH_LOADABLES_PATH =~ (^|:)"$x"($|:) ]] && | |
BASH_LOADABLES_PATH+=${BASH_LOADABLES_PATH:+:}${x} | |
for x in asort mktemp | |
do enable -f "$x"{,} || exit | |
done | |
unset -v x | |
# eeyore arr dir1 dir2... | |
function eeyore { | |
local -; set +m | |
typeset -n ref ret=$1 | |
typeset LC_CTYPE=C IFS spt x y | |
typeset -A src | |
typeset -a dst | |
command shift | |
spt=$(type -P strptime) || return | |
printf -- ${1+'%s\0'} "$@" | | |
find -files0-from - -mindepth 1 -type d -print0 | | |
while IFS= read -rd '' x; do | |
printf %s "${x##*/}" | y=$("$spt" -qi %FT%T+%Z -f %s) && src+=([${y}]=$x) | |
done | |
((!PIPESTATUS[-2])) || return | |
asort -ni dst src | |
for ref in "${dst[@]/*/src[&]}" | |
do ret+=("$ref") | |
done | |
} | |
function m { | |
typeset ret | |
typeset -a a | |
if | |
eeyore a "$@" | |
(( ! ret = $? )) | |
then printf '%q\n' "${a[@]:${#a[@]}-100}" | |
else | |
echo :\( | |
return "$ret" | |
fi | |
} | |
function doTest { | |
local -; set -x | |
typeset -a a | |
typeset n=0 t h | |
mktemp -qdv t || return | |
h=$(type -P head) || return | |
while ((n++ < 200)); do | |
if ! mkdir -p -- "${t}/$(date -ud "@${SRANDOM}" +%FT%T%z)-$(tr -cd '[:alnum:]' </dev/urandom | "$h" -c 8)"; then | |
((n--)) | |
continue | |
fi | |
done | |
m "$t" | |
rm -rf -- "$t" | |
} | |
doTest "$@"; exit | |
# m "$@" | |
# vim: set ft=bash fenc=utf-8 ff=unix ts=4 sw=4 noet : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment