Fix bugs
* Fix env diff for variables containing leading/trailing whitespace * Run whole script in 'clean' (non-direnv) environment (fixes prepending/appending)
parent
cd10903ba1
commit
a498992c2a
11
direnv-cache
11
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"
|
||||
|
@ -87,7 +92,7 @@ case $cmd in
|
|||
source "${cacheFile}.recipe"
|
||||
dumpEnv > "${cacheFile}.post"
|
||||
diffEnvs "${cacheFile}.pre" "${cacheFile}.post" > "$cacheFile"
|
||||
rm "${cacheFile}.pre" "${cacheFile}.post"
|
||||
# rm "${cacheFile}.pre" "${cacheFile}.post"
|
||||
echo "Environment cached in $cacheFile, telling direnv to reload"
|
||||
direnv reload
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue