set -e
target="docs/dev/tasks.md"
begin_marker="<!-- BEGIN GENERATED BY MISE -->"
end_marker="<!-- END GENERATED BY MISE -->"
docs=$(mise generate task-docs)
{
head=""
tail=""
found_begin=false
found_end=false
while IFS= read -r line; do
if [ "$line" = "$end_marker" ]; then
found_end=true
fi
if [ "$found_begin" = true ] && [ "$found_end" = false ]; then
continue
fi
if [ "$found_end" = true ]; then
tail="$tail$line
"
else
head="$head$line
"
fi
if [ "$line" = "$begin_marker" ]; then
found_begin=true
fi
done < "$target"
printf '%s%s\n%s' "$head" "$docs" "$tail" > "$target"
}