#!/usr/bin/env bash # This is an example of a .envrc file for use with direnv. # It sets up the environment for the project. set -euo pipefail : "${PATH_BASE:="$(git rev-parse --show-toplevel)"}" : "${PATH_BIN:="${PATH_BASE}/.bin"}" # Set this environment variable to make sure that within your tests # the command is always named the same : "${ARGSH_SOURCE:="argsh"}" # Define the minimum coverage for the tests # `argsh coverage` will fail if the coverage is below this value : "${MIN_COVERAGE:="70"}" export PATH_BASE PATH_BIN ARGSH_SOURCE MIN_COVERAGE # shellcheck disable=SC2120 path::add() { command -v PATH_add 1>/dev/null || { _error "This can be only run within direnv" return } PATH_add "${1}" } export::env() { local env="${PATH_BASE}/${1}" # shellcheck disable=SC2046 [ ! -f "${env}" ] || { export $(grep -v '^#' "${env}" | sed -E 's/\s+=\s+/=/g' | xargs -d '\n') ! command -v watch_file &>/dev/null || watch_file "${env}" } } copy::template() { local -r file="${PATH_BASE}/${1}" [ -f "${file}" ] || { cp "${file}.template" "${file}" 2>/dev/null || : } } main() { # Use this if you want a template file with example values # make sure to ignore .env and .secrets in your .gitignore copy::template .env copy::template .secrets # This will load the environment variables from the .env and .secrets files export::env .env export::env .secrets # Make your binaries available in the PATH # This is handy to make sure that all developers have the same binaries available path::add "${PATH_BIN:-"${PATH_BASE}/.bin"}" } # Run the main function if this file is sourced by direnv [ -z "${DIRENV_IN_ENVRC}" ] || main "${@}"