# Description: Tiny, lightning fast, feature-packed file manager
# URL: https://github.com/jarun/nnn
# Maintainer: Tim Biermann, tbier at posteo dot de
# Depends on: libpcre2 readline
# Optional: git icons-in-terminal mediainfo patool

name=nnn
version=5.2
release=1
source=(https://github.com/jarun/nnn/releases/download/v$version/$name-v$version.tar.gz)

build() {
  cd $name-$version

  sed -i 's/install: all/install:/' Makefile

  # build with icons support if contrib/icons-in-terminal is installed
  prt-get isinst icons-in-terminal && PKGMK_NNN+=' O_ICONS=1'
  prt-get isinst git && PKGMK_NNN+=' O_GITSTATUS=1'
  prt-get listinst ttf*nerd* && PKGMK_NNN+=' O_NERD=1'

  make $PKGMK_NNN \
    O_NOX11=1 \
    O_RESTOREPREVIEW=1 \
    O_PCRE2=1 \
    O_NOLC=0

  make DESTDIR=$PKG PREFIX=/usr install
  make DESTDIR=$PKG PREFIX=/usr install-desktop

  mkdir $PKG/usr/share/nnn
  # install provided scripts and plugins to $PKG/usr/share
  pushd misc
  for i in $(find . -type d | xargs) ; do
    cp -r $i $PKG/usr/share/nnn;
  done
  popd
  mv plugins $PKG/usr/share/nnn

  # install auto-completion files if the ports for it are installed
  prt-get isinst zsh && install -Dm644 $PKG/usr/share/nnn/zsh/_nnn \
    $PKG/usr/share/zsh/site-functions/_nnn
  prt-get isinst bash-completion && install -Dm644 $PKG/usr/share/nnn/bash/nnn-completion.bash \
    $PKG/usr/share/bash-completion/completions/nnn
  # fish is not in core/opt/contrib, but the script get's installed to

  find $PKG \(\
    -iname '*README.md*' -o \
    -iname '*contributing*' \) -delete
}
