#!/bin/bash
# 一键解决 PATH 问题

echo "🔧 正在修复 PATH 配置..."
echo ""

# 检测使用的 shell
if [ -n "$ZSH_VERSION" ]; then
    SHELL_CONFIG="$HOME/.zshrc"
    SHELL_NAME="zsh"
elif [ -n "$BASH_VERSION" ]; then
    SHELL_CONFIG="$HOME/.bash_profile"
    SHELL_NAME="bash"
else
    echo "❌ 无法检测 shell 类型"
    exit 1
fi

echo "检测到 shell: $SHELL_NAME"
echo "配置文件: $SHELL_CONFIG"
echo ""

# 要添加的 PATH
PYTHON_BIN="$HOME/Library/Python/3.9/bin"
PATH_LINE="export PATH=\"\$HOME/Library/Python/3.9/bin:\$PATH\""

# 检查是否已存在
if grep -q "$PYTHON_BIN" "$SHELL_CONFIG" 2>/dev/null; then
    echo "✅ PATH 已经配置过了"
else
    echo "📝 添加 PATH 到 $SHELL_CONFIG"
    echo "" >> "$SHELL_CONFIG"
    echo "# Python user bin (added by bili-dl)" >> "$SHELL_CONFIG"
    echo "$PATH_LINE" >> "$SHELL_CONFIG"
    echo "✅ PATH 已添加"
fi

echo ""
echo "🔄 重新加载配置..."
source "$SHELL_CONFIG"

echo ""
echo "✅ 配置完成!"
echo ""
echo "📋 验证安装:"
echo "  which bili-dl"
echo "  bili-dl --version"
echo ""
echo "💡 如果命令仍不可用,请:"
echo "  1. 重启终端"
echo "  2. 或运行: source $SHELL_CONFIG"
