#!/bin/bash

# argument: directory path
# prints file count and sum of file sizes

find "$1" -type f -print0 \
	| relpipe-in-filesystem \
		--file path \
		--file size \
	| relpipe-tr-scheme \
		--relation 'f.*' \
		--output-attribute 'count' integer \
		--output-attribute 'sum'   integer \
		--before-records '
			(define $sum   0)
			(define $count 0)
			(define return-sum #f)' \
		--for-each '
			(set! $sum   (+ $sum   $size) )
			(set! $count (+ $count 1    ) )' \
		--where '#f' \
		--after-records '(set! return-sum #t)' \
		--has-more-records '
			(if return-sum
				(begin (set! return-sum #f) #t)
				#f
			)' \
	| relpipe-out-tabular
