# ~/.profile: executed by the command interpreter for login shells.

# Function to safely add directories to PATH
add_to_path() {
    case ":$PATH:" in
        *":$1:"*) ;;
        *) PATH="$1:$PATH" ;;
    esac
}

# Add user directories to PATH
[ -d "$HOME/.local/bin" ] && add_to_path "$HOME/.local/bin"

# Cargo (Rust)
if [ -f "$HOME/.cargo/env" ]; then
    . "$HOME/.cargo/env"
    add_to_path "$HOME/.cargo/bin"
fi

# Bun
if [ -d "$HOME/.bun" ]; then
    export BUN_INSTALL="$HOME/.bun"
    add_to_path "$BUN_INSTALL/bin"
fi

# Custom local environment
[ -f "$HOME/.local/bin/env" ] && . "$HOME/.local/bin/env"

# Rust library path
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib"

# Wayland configuration
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
    systemctl --user import-environment DISPLAY WAYLAND_DISPLAY
fi

# Load bashrc for bash shells
if [ -n "$BASH_VERSION" ] && [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
fi

# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"

export PATH
