~ecs/wersh

0adc67a50cfa80048f35ae0545a30c13d0382a3a — Eyal Sawady 2 months ago adb4d53
Quote more variables

Also add -u
1 files changed, 14 insertions(+), 13 deletions(-)

M wersh
M wersh => wersh +14 -13
@@ 1,5 1,4 @@
#!/bin/sh
set -e
#!/bin/sh -eu

usage() {
	echo "Usage: $0 input/ output/"


@@ 32,6 31,8 @@ render() {
	cat
}

_rendering=
content=
emit() {
	if [ "$_rendering" == "t" ]
	then


@@ 47,8 48,8 @@ escape() {
}

wsource() {
	_file=$(mktemp)
	${_wershawk} < "$1" > "$_file"
	_file="$(mktemp)"
	"${_wershawk}" < "$1" > "$_file"
	. "$_file"
	rm "$_file"
}


@@ 58,13 59,13 @@ preprocessor="cat"
if [ -n "$_single" ]
then
	[ $# -ne 4 ] && usage
	root=$1
	outputdir=$2
	output=$3
	input=$4
	cd $root
	root="$1"
	outputdir="$2"
	output="$3"
	input="$4"
	cd "$root"
	[ -e "$root"/_config.sh ] && . "$root"/_config.sh
	wsource $input
	wsource "$input"
	_rendering=t
	printf "%s" "$content" | $preprocessor | render
else


@@ 81,8 82,8 @@ else
	find "$root" -type f -name "*.w" -not -path "*/_*/*" -not -name "_*" -not -path "/.*" \
	| while read _input
	do
		_output=$_outputdir${_input#$root}
		_output=${_output%.w}
		_output="$_outputdir${_input#$root}"
		_output="${_output%.w}"
		echo "Generating $_output from $_input"
		mkdir -p $(dirname "$_output")
		$0 -s "$root" "$_outputdir" "$_output" "${_input#$root/}" > "$_output"


@@ 90,7 91,7 @@ else
	find "$root" -type f -not -name "*.w" -not -path "*/_*/*" -not -name "_*" -not -path "*/.*" \
	| while read -r _input
	do
		_output=$_outputdir${_input#$root}
		_output="$_outputdir${_input#$root}"
		echo "Copying $_input to $_output"
		mkdir -p $(dirname "$_output")
		cp "$_input" "$_output"