update splitter for stdin

This commit is contained in:
q
2025-11-27 14:21:10 +02:00
parent 67354b492a
commit 290221b0ea

View File

@@ -6,6 +6,7 @@ _help() {
echo ""
echo "My default switches for split utility"
echo "$CMD -b 500M FILE FILE."
echo "if you want to split using stdin, use --stdin pattern"
}
_helpexit() {
_help
@@ -19,17 +20,32 @@ done
args=( )
for (( i=1; i<=$#; i++ )); do
j=$(( i + 1 ))
test -f "${!i}" && {
file="${!i}"
# file found, remove from arguments
set -- "${@:1:i-1}" "${@:i+1}"
}
[[ "${!i}" = "-b" ]] && SIZE_SET=1
[[ "${!i}" = "--stdin" ]] && {
PATTERN="${!j}";
set -- "${@:1:i-1}" "${@:i+2}"
i=$(( i + 1 ));
if [ -z "$PATTERN" ]; then echo must give pattern; exit 1; fi;
}
done
[[ "$SIZE_SET" -eq 1 ]] || {
size="-b 500M"
}
test -f "$file" || { echo "No such file"; exit 1; }
set -x
pv "$file" | $CMD $size "$@" - "$file".
if [[ -n "$PATTERN" ]]; then
set -x
cat - | pv | $CMD $size "$@" - "$PATTERN".
exit
else
test -f "$file" || { echo "No such file"; exit 1; }
set -x
pv "$file" | $CMD $size "$@" - "$file".
fi