postgresfixture 0.3.1

Easily create and manage PostgreSQL clusters on demand for testing and development.
Documentation
#!/usr/bin/env bash
#
# Wrapper script that tries to discover runtimes and add them to `PATH` before
# then executing the command passed in. For example:
#
#   $ cargo run runtimes
#   => 14.2       /usr/local/bin
#
#   $ ./with-runtimes cargo run runtimes
#      9.4.26     /usr/local/Cellar/postgresql@9.4/9.4.26/bin
#      9.5.25     /usr/local/Cellar/postgresql@9.5/9.5.25/bin
#      10.20      /usr/local/Cellar/postgresql@10/10.20_1/bin
#      11.15      /usr/local/Cellar/postgresql@11/11.15_1/bin
#      12.10      /usr/local/Cellar/postgresql@12/12.10_1/bin
#      13.6       /usr/local/Cellar/postgresql@13/13.6_1/bin
#   => 14.2       /usr/local/bin
#
# Note that it adds runtime paths to the _end_ of PATH so that the default
# runtime is not affected.
#

set -euo pipefail

# Debian/Ubuntu.
if [[ -d /usr/lib/postgresql ]]
then
    PATH="$PATH:$(printf '%s:' /usr/lib/postgresql/*/bin)"

# Homebrew.
elif type -P brew > /dev/null
then
    # The most recent version of PostgreSQL – typically installed by the
    # `postgresql` formula – links `pg_ctl` et al. into `$prefix/bin`, and has a
    # Cellar path of `$prefix/Cellar/postgresql` (note: no @version). We
    # specifically do not match it here otherwise it'll be discovered twice and
    # tests, for example, will take longer.
    PATH="$PATH:$(printf '%s:' "$(brew --prefix)"/Cellar/postgresql@*/*/bin)"
fi

# Make sure it's exported. It really should be, but let's be super sure.
export PATH

# Execute whatever we got passed in.
exec "$@"