-
Notifications
You must be signed in to change notification settings - Fork 0
/
.envrc
51 lines (40 loc) · 1.08 KB
/
.envrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -euo pipefail
# This is an example of a .envrc file for use with direnv.
# It sets up the environment for the project.
: "${PATH_BASE:="$(git rev-parse --show-toplevel)"}"
: "${PATH_BIN:="${PATH_BASE}/.bin"}"
: "${ARGSH_SOURCE:="argsh"}"
: "${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() {
copy::template .env
copy::template .secrets
export::env .env
export::env .secrets
path::add "${PATH_BIN:-"${PATH_BASE}/.bin"}"
}
[ -z "${DIRENV_IN_ENVRC}" ] || main "${@}"