Hi,

Matt recently made a PR to a QA check script in Portage [1] which
included the following function:

    is_in() {
        local needle=$1
        shift

        local x
        for x in "$@"; do
            [[ "${needle}" = ${x} ]] && return 0
        done
        return 1
    }

It's more or less `has` but with Bash pattern matching support. The
difference is in how it handles the conditional. For reference, here is
the implementation of `has` in Portage:

    has() {
        local needle=$1
        shift

        local x
        for x in "$@"; do
            [[ "${x}" = "${needle}" ]] && return 0
        done
        return 1
    }

We agreed that it could potentially be useful as something that's
available for general use, so I'd like to propose the idea of adding the
ability to query a list for something like "foo*" or "foob??". Here's
two possibilities for how I would go about implementing it:

1. Add Matt's function. Perhaps as `hasp` (for "has pattern") or
   something.
2. Change `has` to support pattern matching in EAPI 9+

Thoughts?

- Oskari

[1]: https://github.com/gentoo/portage/pull/1034

Attachment: signature.asc
Description: PGP signature

Reply via email to