Created
August 19, 2024 06:19
-
-
Save mrjk/8901c680d393a143cce8ab233ad79d89 to your computer and use it in GitHub Desktop.
Direnv with recurive parent loading support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This snippet allow recurive loading of parent .envrc files | |
# To put in your: ~/.config/direnv/direnvrc | |
# Direnv Recursive mode | |
# ========================= | |
# Disable existing source_up commands | |
source_up () | |
{ | |
echo "WARNING: 'source_up' is disabled from user config" | |
} | |
source_up_if_exists () | |
{ | |
echo "WARNING: 'source_up_if_exists' is disabled from user config" | |
} | |
print_section () | |
{ | |
printf '%s\n' "~~~ ~~~ ~~~ ~~~ ~~~ ~~~" | |
} | |
# Allow recursive source | |
_source_up_all(){ | |
echo "INFO: Direnv source_up recursive mode enabled from user configuration" | |
local file=${1:-.envrc} | |
local all_targets=$(find_up_all $file) | |
local parent_targets=$(sed '1d' <<<"$all_targets" | tac) | |
for i in $parent_targets; do | |
[[ -n "$i" ]] || continue | |
print_section | |
source_env "$i" | |
done | |
print_section | |
} | |
# Load parent configs | |
_source_up_all | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing !
Where are defined find_up_all and tac commands ?