# Contributor: Chloe Kudryavtsev <code@toast.bunkerlabs.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=skim
pkgver=0.10.4
pkgrel=4
pkgdesc="Fuzzy finder written in Rust"
url="https://github.com/lotabout/skim"
# s390x: incompatible with nix crate
# loongarch64: fails to build nix crate
arch="all !s390x !loongarch64"
license="MIT"
makedepends="cargo cargo-auditable"
subpackages="
	$pkgname-doc
	$pkgname-tmux::noarch
	$pkgname-bash-plugin:_bash:noarch
	$pkgname-fish-plugin:_fish:noarch
	$pkgname-vim-plugin:_vim:noarch
	$pkgname-zsh-plugin:_zsh:noarch
	"
install="$pkgname.post-upgrade"
options="net"
source="https://github.com/lotabout/skim/archive/v$pkgver/skim-$pkgver.tar.gz
	replace-perl-with-awk.patch
	include-date-or-time-in-zsh-history-if-avail.patch
	$pkgname.plugin.sh
	$pkgname.plugin.zsh
	"

case "$CARCH" in
	# tests on 32-bit architectures are disabled in upstream CI
	armhf | armv7 | x86) options="!check";;
esac


prepare() {
	default_prepare

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

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

check() {
	cargo test --all --frozen
}

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

	install -Dm644 man/man1/*.1 -t "$pkgdir"/usr/share/man/man1/

	install -Dm644 plugin/skim.vim -t "$pkgdir"/usr/share/vim/vimfiles/plugin/

	install -Dm644 shell/*.bash "$srcdir"/$pkgname.plugin.sh \
		-t "$pkgdir"/usr/share/bash/plugins/$pkgname/

	install -Dm644 shell/key-bindings.fish \
		"$pkgdir"/usr/share/fish/vendor_functions.d/skim-key-bindings.fish

	install -Dm644 shell/*.zsh "$srcdir"/$pkgname.plugin.zsh \
		-t "$pkgdir"/usr/share/zsh/plugins/$pkgname/
}

tmux() {
	pkgdesc="tmux launcher for $pkgname"
	depends="bash"

	amove usr/bin/sk-tmux
}

_vim() {
	pkgdesc="Vim plugin for $pkgname"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel vim"

	amove usr/share/vim
}

_bash() {
	pkgdesc="Bash plugin for $pkgname (completion and key bindings)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel bash"

	amove usr/share/bash/plugins
}

_fish() {
	pkgdesc="Fish key bindings for $pkgname"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel fish"

	amove usr/share/fish
}

_zsh() {
	pkgdesc="Zsh plugin for $pkgname (completion and key bindings)"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel zsh"

	amove usr/share/zsh/plugins
}

sha512sums="
8805552391b5d5850ecda2901eeb4fe70b929977f03d60b113bfcaebfa3601a9ca29acc0df9c418e57f10f878c9725ee796928dd9d92a82a63db24a34da8dfd7  skim-0.10.4.tar.gz
a53783960e1936f001524dae70b78108d8dcce33e899d3736d2bffdfbd009939d2f1a4a14b1778bb46a7d6dfd052fda6be9328889d02c7589ab3fae6a2d1eb38  replace-perl-with-awk.patch
e427e7f70b13cf20387aa3c60e4e9f8514ddd16b49d1673d0ff415ee716511fd3e4d5c5e24cd7ffa3b20ab8bc6edad6ea8a594926cf6f10d8413c21ad3657449  include-date-or-time-in-zsh-history-if-avail.patch
a13ba25c08fe5b54231508be8d2f0a9f4d342630e6c31f2524cc6b8b99cead5b80daa2e2e37a581198f9ce79df2b00fdf81acf84fe1ad8043ee96e4db0870ee6  skim.plugin.sh
4ea4a5511704ef6fe57e7d3187739ba501ddb80d249738310d773edd9e2d08c26d27ec0c8976320e979aa8688984fe591b63a63b3c8589d5b80190e7d85d1c8b  skim.plugin.zsh
"
