# Copyright 2026 Nadeŭka <me+oss@nadevko.cc>
# Distributed under the terms of the GNU General Public License v2
EAPI=9

inherit go-module

DESCRIPTION='Prompt theme engine for any shell'
HOMEPAGE='
	https://ohmyposh.dev
	https://github.com/JanDeDobbeleer/oh-my-posh
'

if [[ $PV == 9999 ]]; then
	inherit git-r3
	EGIT_REPO_URI=https://github.com/JanDeDobbeleer/oh-my-posh.git
else
	SRC_URI="
		https://github.com/JanDeDobbeleer/oh-my-posh/archive/refs/tags/v$PV.tar.gz -> $P.tar.gz
		https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v$PV/$P-deps.tar.xz
	"
	KEYWORDS='amd64 ~arm64 ~x86'
fi
S+=/src

LICENSE=MIT
SLOT=0

IUSE='+themes'

BDEPEND='>=dev-lang/go-1.26.0:='

GOMODCACHE="$WORKDIR/gomodcache"

if [[ $PV == 9999 ]]; then
	src_unpack() {
		git-r3_src_unpack
		go-module_live_vendor
	}
else
	src_unpack() {
		local -x TAR_OPTIONS=--warning=no-unknown-keyword
		default
	}
fi

src_compile() {
	ego build -o oh-my-posh .
}

src_test() {
	ego test -v ./...
}

src_install() {
	dobin oh-my-posh

	cd "$WORKDIR/$P"
	einstalldocs
	if use themes; then
		insinto /usr/share/oh-my-posh/themes
		doins themes/*.json
	fi
}