From a2a56036dabf75b14f21566be95efbacffacb34f Mon Sep 17 00:00:00 2001 From: Alex Ilyaev Date: Tue, 27 Aug 2019 17:48:28 +0300 Subject: [PATCH] Abort if current and target Node versions are the same (closes #78) --- bin/avn.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/avn.sh b/bin/avn.sh index 6c18f87..2741347 100644 --- a/bin/avn.sh +++ b/bin/avn.sh @@ -47,9 +47,18 @@ function __avn_chpwd() { local file=$(__avn_find_file) local dir=${file%/*} local name=${file##*/} + local VERSION_REGEX="[0-9]+\.[0-9]+\.[0-9]+" + + if [[ -n "$file" ]] && [[ "$file" != "$__avn_active_file" ]]; then + [[ $(node -v) =~ $VERSION_REGEX ]] && currentNodeVersion=${BASH_REMATCH} + [[ $(head -n 1 $file) =~ $VERSION_REGEX ]] && targetNodeVersion=${BASH_REMATCH} + + # Abort if the current and target node versions are the same + # https://github.com/wbyoung/avn/issues/78 + [[ $currentNodeVersion == $targetNodeVersion ]] && return 0 - [[ -n "$file" ]] && [[ "$file" != "$__avn_active_file" ]] && __avn_eval chpwd "$dir" "$name" || true + fi __avn_active_file=$file