From 80e349edb14869eb29a4b5bb581402eb98ba7142 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 30 Apr 2014 10:31:51 +0200 Subject: [PATCH] locate .nvmrc without `find` instead of using find and actually cd'ing into directories we're now using simple string replacement on the `pwd` --- nvm.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/nvm.sh b/nvm.sh index 6f0b955..1523b80 100644 --- a/nvm.sh +++ b/nvm.sh @@ -34,14 +34,22 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist" fi -nvm_find_nvmrc() { - typeset dir="$PWD" - typeset found="" - while [ "$dir" != "/" ] && [ "$found" = "" ]; do - found=$(find "$dir" -maxdepth 1 -name ".nvmrc") - dir=$(cd "$dir/.." && pwd -P) +# Traverse up in directory tree to find containing folder +nvm_find_up() { + local path + path=$(pwd) + while [[ "$path" != "" && ! -e "$path/$1" ]]; do + path=${path%/*} done - echo $found + echo "$path" +} + + +nvm_find_nvmrc() { + local dir=$(nvm_find_up '.nvmrc') + if [ -e "$dir/.nvmrc" ]; then + echo "$dir/.nvmrc" + fi } # Obtain nvm version from rc file