#!/usr/bin/env python3

import os
import subprocess

FILE = "Brewfile"

if os.path.exists(FILE):
    os.remove(FILE)

subprocess.run(["brew", "bundle", "dump", "--describe", "--no-cargo"])

with open(FILE) as file:
    lines = file.readlines()

i = 0
while i < len(lines):
    if lines[i].startswith("#"):
        lines.insert(i, "\n")
        i += 1
    i += 1

with open(FILE, "w") as file:
    file.write("".join(lines))
