# Maintainer: John Khoo <john underscore khoo AT u dot nus DOT edu>
# Contributor:
# Adapted from Arch PKGBUILD: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=nnn-git

pkgname=nnn
pkgver=5.1
pkgrel=2
pkgdesc="The fastest terminal file manager ever written."
arch=(i686 x86_64)
url='https://github.com/jarun/nnn'
license=('spdx:BSD-2-Clause')
depends=(
  'bash'
  'ncurses'
  'libreadline'
)
optdepends=(
  'atool: for more archive formats'
  'libarchive: for more archive formats'
  'zip: for zip archive format'
  'unzip: for zip archive format'
  'rclone: mount remotes'
)
makedepends=(gcc libreadline-devel ncurses-devel pkgconf)
source=("https://github.com/jarun/nnn/releases/download/v${pkgver}/nnn-v${pkgver}.tar.gz")
sha256sums=('c88af1c6eea22e0638a617da2e3103cc1d9b4b3817404db7ca2cb2c05208ec45')

prepare() {
  cd "nnn-${pkgver}"
  sed -i 's/install: all/install:/' Makefile
}

build() {
  cd "nnn-${pkgver}"
  make
}

package() {
  cd "nnn-${pkgver}"
  make DESTDIR="${pkgdir}" PREFIX=/usr strip install

  install -Dm644 misc/auto-completion/fish/nnn.fish "${pkgdir}/usr/share/fish/vendor_completions.d/nnn.fish"
  install -Dm644 misc/auto-completion/bash/nnn-completion.bash "${pkgdir}/usr/share/bash-completion/completions/nnn"
  install -Dm644 misc/auto-completion/zsh/_nnn "${pkgdir}/usr/share/zsh/site-functions/_nnn"

  install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
