diff --git a/direnv-cache b/direnv-cache index 4dc30fd..f0a4972 100755 --- a/direnv-cache +++ b/direnv-cache @@ -30,14 +30,14 @@ diffEnvs() { local old="$1" local new="$2" - while read -r -d '' line; do + while IFS= read -r -d '' line; do name=$(tr -d '\0' <<<"$line" | head -n1 | cut -f1 -d'=') if ! getByName "$name" "$new" >/dev/null; then echo "export -n '${name}'" fi done <"$old" - while read -rd $'\0' line; do + while IFS= read -rd $'\0' line; do name=$(tr -d '\0' <<<"$line" | head -n1 | cut -f1 -d'=') if getByName "$name" "$old" >/dev/null; then # found in old env, check if values match @@ -77,6 +77,11 @@ cacheFile=$(getCacheFilePath) case $cmd in reload|r) + if [[ -n $DIRENV_DIR ]]; then + # run self in clean environment (i.e. outside of the current direnv + # environment) + exec direnv exec /proc "${BASH_SOURCE[0]}" "$@" + fi echo "Re-creating cache" mkdir -p "$(dirname ${cacheFile})" dumpEnv > "${cacheFile}.pre"