#!/usr/bin/env bash # Look for any Caddyfiles in the current directory, and use `caddy fmt` # to format them. # # This skips any Caddyfiles that contain `[[[cog`, which is a sign that # they use Cog for templates: https://alexwlchan.net/2026/cog-in-my-caddy/ set -o errexit set -o nounset format_caddyfile() { caddy fmt "$1" >/dev/null 2>&1 if (( $? != 0 )); then echo "$1" caddy fmt --overwrite "$1" fi } export -f format_caddyfile find . \( -name Caddyfile -o -name '*.Caddyfile' \) -print0 \ | xargs -0 grep -L '\[\[\[cog' \ | xargs -I '{}' bash -c 'format_caddyfile "$1"' _ {}