# Maintainer: justin13888 <20733699+justin13888@users.noreply.github.com>
pkgname=purr-git
pkgver=1.0.0
pkgrel=1
pkgdesc="Fast, neofetch-compatible system information tool (built from git)"
arch=('x86_64' 'aarch64')
url="https://github.com/justin13888/purrfetch"
license=('MIT')
makedepends=('cargo' 'git')
provides=('purr')
conflicts=('purr')
source=("$pkgname::git+https://github.com/justin13888/purrfetch.git")
sha256sums=('SKIP')

pkgver() {
	cd "$srcdir/$pkgname"
	git describe --long --tags --abbrev=7 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' \
		|| printf 'r%s.%s' "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
}

prepare() {
	cd "$srcdir/$pkgname"
	export RUSTUP_TOOLCHAIN=stable
	cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
	cd "$srcdir/$pkgname"
	export RUSTUP_TOOLCHAIN=stable
	export CARGO_TARGET_DIR=target
	cargo build --frozen --release
}

check() {
	cd "$srcdir/$pkgname"
	export RUSTUP_TOOLCHAIN=stable
	cargo test --frozen --release
}

package() {
	cd "$srcdir/$pkgname"
	install -Dm755 target/release/purr "$pkgdir/usr/bin/purr"
	install -Dm644 man/purr.1 "$pkgdir/usr/share/man/man1/purr.1"
	install -Dm644 completions/purr.bash "$pkgdir/usr/share/bash-completion/completions/purr"
	install -Dm644 completions/_purr "$pkgdir/usr/share/zsh/site-functions/_purr"
	install -Dm644 completions/purr.fish "$pkgdir/usr/share/fish/vendor_completions.d/purr.fish"
	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
