#!/usr/bin/env bash
name='nano'
release='6'
version='9.0'
url='https://www.nano-editor.org/download.php'
description='Pico editor clone with enhancements'
email='parduscix@yandex.ru'
maintainer='sulincix'
license=('GPLv3')
_commit="359cc2b641a55579cef347451b064061fbc00aaf"
source=("https://www.nano-editor.org/dist/v9/nano-$version.tar.xz"
        "https://github.com/galenguyer/nano-syntax-highlighting/archive/${_commit}.zip"
        "nanorc"
        "nano.desktop"
        "icon.svg")
depends=(file zlib ncurses bzip2)
makedepends=()
sha256sums=('9f384374b496110a25b73ad5a5febb384783c6e3188b37063f677ac908013fde'
            '107de8e981952c5995fb03163fa4760a6f9d864eff0cf22115dd1e1566fe3c17'
            'SKIP'
            'SKIP'
            'SKIP'
)
uses=(nanorc)
arch=('x86_64')
group=(app.editor)

cd $name-$version

prepare(){
    # fake makeinfo command
    echo > ~/makeinfo
    chmod 755 ~/makeinfo
}

setup(){
    autoreconf -fvi
    ./configure --prefix=/usr \
        --sysconfdir=/etc \
        --libdir=/usr/lib64/ \
        $(use_arg nanorc --enable-color --disable-color )\
        $(use_arg nanorc --enable-nanorc --disable-nanorc )\
        --enable-multibuffer
}

build(){
    make $jobs
}

package(){
    make install $jobs
    mkdir -p ${DESTDIR}/etc
    install ../nanorc ${DESTDIR}/etc/nanorc
    # install extra nanorc files
    cd ../nano-syntax-highlighting-${_commit}
    for file in ./*.nanorc ; do
        if [[ ! -f ${DESTDIR}/usr/share/nano/$file ]] ; then
            # black color is buggy with dark themes so replace with green
            sed -i "s/color black/ color green/g" $file
            sed -i "s/color brightblack/ color brightgreen/g" $file
            install $file ${DESTDIR}/usr/share/nano/
        fi
    done
    # install application launcher for desktop environments
    mkdir -p ${DESTDIR}/usr/share/applications/
    mkdir -p ${DESTDIR}/usr/share/icons/hicolor/scalable/apps/
    install ../nano.desktop ${DESTDIR}/usr/share/applications
    install ../icon.svg ${DESTDIR}/usr/share/icons/hicolor/scalable/apps/nano.svg

}
