# paralleli.sh - kinda like GNU Parallel but not GNU
# v2.0, 2023-09-06, ed <irc.rizon.net>, MIT-Licensed
# https://ocv.me/dev/?paralleli.sh

# just kidding, this isn't a new version, more like a deprecation notice
# since just using xargs instead is way better (and that also avoids a
# bash resource leak which the original parallelish was hitting)

# put this into your .bashrc:

par() {
    type paf >/dev/null || {
        printf '%s\n' 'try this:' 'paf() { echo "processing file $1 ..."; sleep 1; }' 'find -type f -print0 | par  # -t'
        return 1
    }
    export -f paf
    xargs "$@" -0i -P$(nproc) bash -c 'paf "$@"' _ {}
}

# example: OCR a folder of screenshots into a subfolder named txt:
# paf() { mode=12; o="txt/$1.tess.$mode.txt"; [ -e "$o" ] && return; tesseract "$1" - --psm $mode > "$o"; }
# find -maxdepth 1 -type f -iname '*.png' -print0 | par -t

