#!/bin/bash

echo "🚀 Oh My Posh Setup Script (Catppuccin Mocha)"

read -p "Do you want to install or uninstall? (install/uninstall): " choice

if [[ "$choice" == "install" ]]; then
    echo "➡️ Installing..."

    sudo apt update -y
    sudo apt install wget unzip fonts-powerline -y

    sudo wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
    sudo chmod +x /usr/local/bin/oh-my-posh

    echo "✅ Oh My Posh version:"
    oh-my-posh --version

    mkdir -p ~/.poshthemes
    wget https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/catppuccin_mocha.omp.json -O ~/.poshthemes/catppuccin_mocha.omp.json

    sed -i 's/{{ .UserName }}@{{ .HostName }}/vandine-5858/g' ~/.poshthemes/catppuccin_mocha.omp.json
    sed -i 's/"type": "session"/"type": "text"/g' ~/.poshthemes/catppuccin_mocha.omp.json

    if ! grep -q "oh-my-posh init bash" ~/.bashrc; then
      echo 'eval "$(oh-my-posh init bash --config ~/.poshthemes/catppuccin_mocha.omp.json)"' >> ~/.bashrc
    fi

    mkdir -p ~/.local/share/fonts
    cd ~/.local/share/fonts
    wget -q https://github.com/ryanoasis/nerd-fonts/releases/latest/download/JetBrainsMono.zip
    unzip -o JetBrainsMono.zip >/dev/null
    fc-cache -fv >/dev/null

    cd ~
    source ~/.bashrc

    echo "🎨 Installation complete!"
    echo "➡️ Set your terminal font to 'JetBrainsMono Nerd Font' for best appearance."
    echo "✅ You should now see your Catppuccin Mocha prompt as:  vandine -5858~ "

elif [[ "$choice" == "uninstall" ]]; then
    echo "➡️ Uninstalling..."

    # Remove Oh My Posh binary
    sudo rm -f /usr/local/bin/oh-my-posh

    # Remove theme folder
    rm -rf ~/.poshthemes

    # Remove Nerd Fonts folder
    rm -rf ~/.local/share/fonts

    # Remove Oh My Posh line from .bashrc
    sed -i '/oh-my-posh init bash/d' ~/.bashrc

    # Reload bash
    source ~/.bashrc

    echo "❌ Uninstallation complete! Your terminal prompt is back to default."
else
    echo "⚠️ Invalid option. Please run the script again and choose install or uninstall."
fi