pkgname=ripgrep
pkgver=14.1.1
pkgdesc="A search tool that combines the usability of ag with the raw speed of grep"
arch=('x86_64')
homepage="https://github.com/BurntSushi/ripgrep"
license=('MIT OR Unlicense')
depends=(
  'gcc-libs'
  'glibc'
  'pcre2'
)
makedepends=('rust')
sources=("${pkgname}-${pkgver}.tar.gz")
urls=("${homepage}/archive/${pkgver}/${sources[0]}")
md5sums=("80fada3fb311956fb0e26f89e8115bf4")

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
}

src_build() {
  cargo build --release --locked --features 'pcre2'
}

src_check() {
  cargo test --release --locked --features 'pcre2'
}

src_install() {
  install -vDm755 -t "$pkgdir/usr/bin" target/release/rg

  mkdir -vp "$pkgdir/usr/share/zsh/site-functions"
  target/release/rg --generate complete-zsh > "$pkgdir/usr/share/zsh/site-functions/_rg"

  mkdir -vp "$pkgdir/usr/share/bash-completion/completions"
  target/release/rg --generate complete-bash > "$pkgdir/usr/share/bash-completion/completions/rg"

  mkdir -vp "$pkgdir/usr/share/fish/vendor_completions.d"
  target/release/rg --generate complete-fish > "$pkgdir/usr/share/fish/vendor_completions.d/rg.fish"

  mkdir -vp "$pkgdir/usr/share/man/man1"
  target/release/rg --generate man > "$pkgdir/usr/share/man/man1/rg.1"

  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" COPYING
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE-MIT
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" UNLICENSE
}

# vim:ft=sh syn=sh et sw=2:
