# This is an example PKGBUILD file. Use this as a start to creating your own,
# and remove these comments. For more information, see 'man PKGBUILD'.
# NOTE: Please fill out the license field for your package! If it is unknown,
# then please put 'unknown'.

# Maintainer: Your Name <youremail@domain.com>
pkgname=gitnore-git
_reponame=gitnore
pkgver=VERSION
pkgrel=1
epoch=
pkgdesc="Quickly generate gitignore files from presets."
arch=(x86_64)
url="https://git.samuelcollins.dev/Sam/gitnore"
license=('MIT')
groups=()
depends=()
makedepends=(cargo)
checkdepends=()
optdepends=()
provides=(gitnore)
conflicts=(gitnore)
source=(git+$url.git)
noextract=()
md5sums=(SKIP)

pkgver() {
  cd gitnore
  git describe --long --tags | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
  cd "$srcdir/$_reponame"

  GITNORE_VERSION=$pkgver cargo build --locked --release --target-dir target
  mkdir completions
  ./target/release/gitnore --completions bash > completions/bash
  ./target/release/gitnore --completions fish > completions/fish
  ./target/release/gitnore --completions zsh > completions/zsh

}

package() {
  cd "$srcdir/$_reponame"
  install -Dm755 target/release/gitnore "${pkgdir}/usr/bin/gitnore"
  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  # Shell completions
  install -Dm644 completions/bash "${pkgdir}/usr/share/bash-completion/completions/gitnore.bash"
  install -Dm644 completions/fish "${pkgdir}/usr/share/fish/vendor_completions.d/gitnore.fish"
  install -Dm644 completions/zsh "${pkgdir}/usr/share/zsh/site-functions/_gitnore"
}
