UNPKG

644 Bapplication/x-shView Raw
1#!/usr/bin/env bash
2
3# Load behavior of local `.envrc` files
4function 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
21function custom_cd() {
22 builtin cd $@
23 tryLoadEnvrc ${*: -1:1}
24}
25alias cd='custom_cd'
26
27tryLoadEnvrc