1 |
|
2 |
|
3 | # Load behavior of local `.envrc` files
|
4 | function tryLoadEnvrc() {
|
5 | local current="${PWD}"
|
6 | local maxDepth=20
|
7 | local depth=0
|
8 | while [[ ${current} != ~ ]] && [[ ${current} != "/" ]] && [[ ${depth} -lt ${maxDepth} ]]
|
9 | do
|
10 | envrcPath=${current}/.envrc
|
11 | # Look for the script and load it
|
12 | if [[ -f ${envrcPath} ]]; then
|
13 | source ${envrcPath}
|
14 | fi
|
15 | current="$(dirname "${current}")"
|
16 | depth=$((${depth}+1))
|
17 | done
|
18 | }
|
19 |
|
20 | # Wrapper of the custom cd to inject the load behavior
|
21 | function custom_cd() {
|
22 | builtin cd $@
|
23 | tryLoadEnvrc ${*: -1:1}
|
24 | }
|
25 | alias cd='custom_cd'
|
26 |
|
27 | tryLoadEnvrc
|