# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=eza
pkgver=0.21.3
pkgrel=0
pkgdesc="ls replacement written in Rust"
url="https://github.com/eza-community/eza"
arch="all"
license="MIT"
makedepends="
	cargo
	cargo-auditable
	libgit2-dev
	zlib-dev
	"
# For backward compatibility (Alpine <3.19), exa has been renamed to eza.
provides="exa=$pkgver-r$pkgrel"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/eza-community/eza/archive/v$pkgver/eza-$pkgver.tar.gz
	completions-exa.patch
	"
options="net"

# man pages are generated by pandoc which is available only on x86_64 and aarch64.
case "$CARCH" in x86_64 | aarch64)
	makedepends="$makedepends just pandoc-cli"
	subpackages="$subpackages $pkgname-doc"
esac

# secfixes:
#   0.18.2-r0:
#     - CVE-2024-24577

export LIBGIT2_NO_VENDOR=1  # use system libgit2

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release

	if command -v pandoc >/dev/null; then
		just man
	fi
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 target/release/eza -t "$pkgdir"/usr/bin/

	install -Dm644 completions/bash/* -t "$pkgdir"/usr/share/bash-completion/completions/
	install -Dm644 completions/fish/* -t "$pkgdir"/usr/share/fish/vendor_completions.d/
	install -Dm644 completions/zsh/* -t "$pkgdir"/usr/share/zsh/site-functions/

	if command -v pandoc >/dev/null; then
		install -Dm644 target/man/eza.1 -t "$pkgdir"/usr/share/man/man1/
		install -Dm644 target/man/eza_colors.5 -t "$pkgdir"/usr/share/man/man5/
		install -Dm644 target/man/eza_colors-explanation.5 -t "$pkgdir"/usr/share/man/man5/
	fi

	# Symlinks for backward compatibility (exa has been renamed to eza).
	ln -s eza "$pkgdir"/usr/bin/exa
}

sha512sums="
6e8e3b03abf096891538e2eab7c7a6d7c7bb05f98801db350fcd8c57247f63a423897c8725deace3b21fa718063c5823eee510f1d913aefeb7888230c6b3e232  eza-0.21.3.tar.gz
a6d4139bc1e420ad85e88611551ed79274a6a994f1db1bb29cf833145c2c8be816d6ed540ce4f1393431c607dbb2755519f464f40ab9f163545f49cf78eeb12b  completions-exa.patch
"
