From 6fb279eca090be50c642ac0fb38ebb9ef05f07d3 Mon Sep 17 00:00:00 2001 From: 0xee Date: Mon, 3 Feb 2020 11:33:25 +0100 Subject: [PATCH] Allow calling direnv-cache from subdirectories of $DIRENV_DIR --- direnv-cache | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/direnv-cache b/direnv-cache index 17370ce..9b45f20 100755 --- a/direnv-cache +++ b/direnv-cache @@ -70,9 +70,23 @@ getCacheFilePath() { echo "${cacheDir}/$(pwd | sha1sum | tr -d ' -')" } +switchToDirenvDir() { + # Find directory that contains the current .envrc. Allows direnv-cache to + # be called from subdirectories. + wd="$(pwd)" + + if [[ -n $DIRENV_DIR ]]; then + wd="${DIRENV_DIR#-}" + fi + + cd "$wd" +} + cmd="$1" -if ! [[ -e .envrc ]]; then +switchToDirenvDir + +if ! [[ -e ".envrc" ]]; then echo "Error, no .envrc found in current directory" exit 1 fi