# 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.0
pkgrel=1
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)
source=("https://github.com/jarun/nnn/releases/download/v${pkgver}/nnn-v${pkgver}.tar.gz")
sha256sums=('ba82d6c685bb3687521de2f576244f82558a4af9afeeedda434d5ecb1c029520')

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"
}
