summaryrefslogtreecommitdiff
path: root/src/pre
blob: d593ad2763948a52959a9b8c7f26a318e89ce1a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
set -eu

usage() {
	cat <<-'EOF'
		Usage:
		  pre PREFIX < STDIN
	EOF
}


SEP=:
while getopts 'n' flag; do
	case "$flag" in
		(n)
			SEP=
			;;
		(*)
			usage >&2
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))


PREFIX="${1:-}"
eval "$(assert-arg -- "$PREFIX" 'PREFIX')"

# FIXME: using "while" so we avoid GNU sed's buffering
while read -r line; do
	printf '%s%s %s\n' "$PREFIX" "$SEP" "$line"
done