# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=eza
pkgver=0.19.0
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

prepare() {
	default_prepare

	cargo update time
	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="
a859501709a38787481bcd0d6b1a29f29a35f2e5c0fe1e1ce507f852786c840745baf7e52230b35864fb39b3f6300edf2c520615789ce75d572b350464ca10da  eza-0.19.0.tar.gz
a6d4139bc1e420ad85e88611551ed79274a6a994f1db1bb29cf833145c2c8be816d6ed540ce4f1393431c607dbb2755519f464f40ab9f163545f49cf78eeb12b  completions-exa.patch
"
