# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=zoxide
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.8
pkgrel=1
pkgdesc="A smarter cd command (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/ajeetdsouza/zoxide'
msys2_references=(
  'purl: pkg:cargo/zoxide'
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
checkdepends=('fish' 'zsh')
options=('!strip')
source=("https://github.com/ajeetdsouza/zoxide/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1b276edbf328aafc86afe1ebce41f45ccba3a3125412e89c8c5d8e825b0c7407')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 contrib/completions/zoxide.bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/zoxide"
  install -Dm644 contrib/completions/_zoxide "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_zoxide"
  install -Dm644 contrib/completions/zoxide.fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/zoxide.fish"
  install -Dm644 man/man1/* -t "${pkgdir}${MINGW_PREFIX}/share/man/man1/"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
