web/caddyfmt
- 603 bytes
- View raw
1#!/usr/bin/env bash
2# Look for any Caddyfiles in the current directory, and use `caddy fmt`
3# to format them.
4#
5# This skips any Caddyfiles that contain `[[[cog`, which is a sign that
6# they use Cog for templates: https://alexwlchan.net/2026/cog-in-my-caddy/
8set -o errexit
9set -o nounset
11format_caddyfile() {
12 caddy fmt "$1" >/dev/null 2>&1
13 if (( $? != 0 )); then
14 echo "$1"
15 caddy fmt --overwrite "$1"
16 fi
17}
19export -f format_caddyfile
21find . \( -name Caddyfile -o -name '*.Caddyfile' \) -print0 \
22 | xargs -0 grep -L '\[\[\[cog' \
23 | xargs -I '{}' bash -c 'format_caddyfile "$1"' _ {}