#!/usr/bin/env bash
set -euo pipefail

FISH_CONFIG_DIR="${HOME}/.config/fish"
FISH_FUNCTIONS_DIR="${FISH_CONFIG_DIR}/functions"
FISH_CONFIG_FILE="${FISH_CONFIG_DIR}/config.fish"
FISH_PROMPT_FILE="${FISH_FUNCTIONS_DIR}/fish_prompt.fish"


if ! command -v dnf >/dev/null 2>&1; then
    echo "This script is for Fedora systems with dnf."
    exit 1
fi


sudo dnf install -y htop tree git gcc gcc-c++ make cmake fish vim

curl -LsSf https://astral.sh/uv/install.sh | sh

if ! sudo dnf install -y uv; then
    echo "uv package is not available in the currently enabled Fedora repositories."
fi

mkdir -p "${FISH_FUNCTIONS_DIR}"
touch "${FISH_CONFIG_FILE}"

if ! grep -qxF 'set -g fish_greeting' "${FISH_CONFIG_FILE}"; then
    printf '\nset -g fish_greeting\n' >> "${FISH_CONFIG_FILE}"
fi

cat > "${FISH_PROMPT_FILE}" <<'EOF'
function fish_prompt
    set -l last_status $status

    set_color brblue
    printf '%s' (prompt_pwd)
    set_color normal

    if test $last_status -ne 0
        printf ' '
        set_color red
        printf '[%s]' $last_status
        set_color normal
    end

    printf '\n'
    set_color brcyan
    printf '> '
    set_color normal
end
EOF

echo "Installed: htop tree git gcc gcc-c++ make cmake fish"
echo "Fish prompt configured. Start it with: fish"
