# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=oh-my-posh
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=23.9.1
pkgrel=1
pkgdesc="A prompt theme engine for any shell (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/JanDeDobbeleer/oh-my-posh"
msys2_documentation_url="https://ohmyposh.dev"
msys2_references=(
    'aur: oh-my-posh'
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-go"
             "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-ttf-font-nerd: to have icons in prompt themes")
source=("https://github.com/JanDeDobbeleer/oh-my-posh/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('21711cdc29092101b54712fef2692f77b38e3cffde33a4e218ed30a039031338')

build() {
    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

    cd "${_realname}-${pkgver}/src"
    go build \
      -ldflags="-linkmode=external \
      -X github.com/jandedobbeleer/oh-my-posh/src/build.Version=${pkgver} \
      -X github.com/jandedobbeleer/oh-my-posh/src/build.Date=$(date +%F)" \
      -o "${_realname}.exe"
}

package() {
    cd "${_realname}-${pkgver}/src"
    install -Dm755 "${_realname}.exe" "${pkgdir}${MINGW_PREFIX}/bin/${_realname}.exe"
    install -Dm644 "../COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
    install -Dm644 ../themes/* -t "${pkgdir}${MINGW_PREFIX}/share/oh-my-posh/themes"

    local _complete="./${_realname} completion"
    $_complete bash | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/${_realname}"
    $_complete fish | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/${_realname}.fish"
    $_complete zsh | install -Dm644 /dev/stdin "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_${_realname}"
}
