#!/bin/bash

# Define the pip config directory and file
PIP_CONFIG_DIR="$HOME/.config/pip"
PIP_CONFIG_FILE="$PIP_CONFIG_DIR/pip.conf"

# Create the config directory if it doesn't exist
mkdir -p "$PIP_CONFIG_DIR"

# Add or update the break-system-packages option
if grep -q "^\[install\]" "$PIP_CONFIG_FILE" 2>/dev/null; then
    # [install] section exists; update or append the option
    if grep -q "^break-system-packages" "$PIP_CONFIG_FILE"; then
        sed -i 's/^break-system-packages.*/break-system-packages = true/' "$PIP_CONFIG_FILE"
    else
        sed -i '/^\[install\]/a break-system-packages = true' "$PIP_CONFIG_FILE"
    fi
else
    # Add the [install] section and the option
    {
        echo "[install]"
        echo "break-system-packages = true"
    } >> "$PIP_CONFIG_FILE"
fi

echo "✅ pip is now configured to use --break-system-packages by default."