#!/bin/bash
# filepath: /Users/vhpfi/dotfiles/lk-installers/macinstaller

# Check if Homebrew is installed
if command -v brew >/dev/null 2>&1; then
    echo "Homebrew is already installed. Updating..."
    brew update
else
    echo "Homebrew not found. Installing Homebrew..."
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    # Add Homebrew to PATH for the current session
    if [[ -f /opt/homebrew/bin/brew ]]; then
        # For Apple Silicon Macs
        eval "$(/opt/homebrew/bin/brew shellenv)"
        echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
        echo "Homebrew has been installed and added to your PATH."
    elif [[ -f /usr/local/bin/brew ]]; then
        # For Intel Macs
        eval "$(/usr/local/bin/brew shellenv)"
        echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
        echo "Homebrew has been installed and added to your PATH."
    else
        echo "Error: Couldn't find the Homebrew binary after installation."
        exit 1
    fi
fi

echo "Installing packages with Homebrew..."
brew install neovim btop htop neofetch curl wget git zip unzip zsh tldr
brew install zsh-autosuggestions zsh-syntax-highlighting 
brew install rustup-init
rustup-init -y

echo "Installation complete!"