# $Id: Portfile 118693 2014-04-08 10:26:23Z raimue@macports.org $

PortSystem      1.0

name            bash-completion
conflicts       bash-completion-devel
epoch           1
version         2.1
revision        8
categories      sysutils
platforms       darwin
supported_archs noarch
license         GPL-2+
maintainers     raimue
description     Programmable bash completions
long_description \
    Programmable completion library for bash. This port requires bash >=4.1 and \
    is meant to be used together with the bash port.

homepage        http://bash-completion.alioth.debian.org/
master_sites    http://bash-completion.alioth.debian.org/files/
checksums       md5     4e2a9f11a4042a38ee79ddcd048e8b9e \
                rmd160  5e019214ee2c7788ef7d80179e30594047b23a37 \
                sha256  2b606804a7d5f823380a882e0f7b6c8a37b0e768e72c3d4107c51fbe8a46ae4f
use_bzip2 yes

depends_run     port:bash

patchfiles      patch-vpnc.diff \
                patch-make.diff \
                patch-_known_hosts_real.diff \
                patch-compat-dont-return.diff \
                patch-words-bad-array-subscript.diff \
                patch-fix-quote-readline-by-ref.diff \
                patch-perldoc-pod.diff

post-patch {
    reinplace "s:/etc/bash_completion:${prefix}/etc/bash_completion:g" \
        ${worksrcpath}/bash_completion
    reinplace "s:readlink -f:readlink:g" \
        ${worksrcpath}/bash_completion

    # Fix vpnc config location, #29281
    reinplace "s:@@PREFIX@@:${prefix}:g" \
        ${worksrcpath}/completions/vpnc
}

post-destroot {
    xinstall -m 644 -W ${filespath} port launchctl \
        ${destroot}${prefix}/share/bash-completion/completions/

    # Add a link for compatibility with versions <2.0 of this port
    ln -s ${prefix}/etc/profile.d/bash_completion.sh ${destroot}${prefix}/etc/bash_completion
}

notes "
To use bash_completion, add the following lines at the end of your .bash_profile:
  if \[ -f ${prefix}/etc/profile.d/bash_completion.sh ]; then
      . ${prefix}/etc/profile.d/bash_completion.sh
  fi
"

if {${os.platform} eq "darwin" && ${os.subplatform} eq "macosx"} {
    # Insert an empty line into the notes
    notes-append ""
    notes-append "
        The port bash-completion >=2.0 requires bash >=4.1; please make sure
        you are using ${prefix}/bin/bash by changing the preferences of your
        terminal accordingly. If your version of bash is too old, the script
        above will not modify your shell environment and no extended completion
        will be available.
    "
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
