# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem              1.0
PortGroup               github 1.0
PortGroup               makefile 1.0
PortGroup               xcodeversion 1.0

minimum_xcodeversions   {19 12.0}

github.setup            FelixKratz SketchyBar 2.21.0 v
github.tarball_from     archive

categories              sysutils
maintainers             {@bashu gmail.com:bashu.was.here} openmaintainer
license                 GPL-3
name                    sketchybar
revision                0
supported_archs         x86_64 arm64
description             Custom macOS statusbar with shell plugin, interaction and graph support
long_description        This bar project aims to create a highly flexible, \
                        customizable, fast and powerful status bar replacement \
                        for people that like playing with shell scripts.

checksums               rmd160  31c36e7a2cc2880b00d89a34f4907b1cc9bee5b4 \
                        sha256  7a35b4079467d7b52edfa103ae33deb0be4133291c32ca4157ba38a9a0742f2a \
                        size    1666781

post-extract {
    file copy ${filespath}/org.macports.${name}.plist ${worksrcpath}/org.macports.${name}.plist
}

post-patch {
    reinplace "s|@NAME@|${name}|g" ${worksrcpath}/org.macports.${name}.plist
    reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/org.macports.${name}.plist
}


if {${configure.build_arch} == "x86_64"} {
    build.target "x86"
} elseif {${configure.build_arch} == "arm64"} {
    build.target "arm64"
} elseif {${universal_possible}} {
    build.target "universal"
}

destroot {
    # Copy binary
    xinstall -m 755 ${worksrcpath}/bin/sketchybar ${destroot}${prefix}/bin/sketchybar

    # Copy example files
    xinstall -d -m 0755 ${destroot}${prefix}/share/doc/${name}/examples
    copy ${worksrcpath}/plugins ${destroot}${prefix}/share/doc/${name}/examples
    copy ${worksrcpath}/sketchybarrc ${destroot}${prefix}/share/doc/${name}/examples

    set launchd_dir ${prefix}/etc/${startupitem.location}/${startupitem.uniquename}/
    xinstall -m 0755 -d ${destroot}/${launchd_dir}
    xinstall -m 0644 ${worksrcpath}/${startupitem.plist} ${destroot}${launchd_dir}

    # install the plist, if startupitem.install is set
    if {[getuid] == 0  && ${startupitem.install}} {
        xinstall -m 0755 -d ${destroot}/Library/${startupitem.location}
        ln -sf ${launchd_dir}${startupitem.plist} ${destroot}/Library/${startupitem.location}
    } else {
        ln -sf ${launchd_dir}/${startupitem.plist} ${destroot}${prefix}/etc/${startupitem.location}
    }
}

notes "
Copy the example configuration into your home directory and make the scripts executable:

     mkdir ~/.config/${name}
     cp ${prefix}/share/doc/${name}/examples/sketchybarrc ~/.config/${name}/sketchybarrc

     mkdir ~/.config/${name}/plugins
     cp -r ${prefix}/share/doc/${name}/examples/plugins/ ~/.config/${name}/plugins/

     chmod +x ~/.config/${name}/plugins/*
"

startupitem.create      no
startupitem.autostart   no
startupitem.location    LaunchAgents
startupitem.executable  ${prefix}/bin/sketchybar
