Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvm does not work, if CDPATH is set #32

Closed
AlexanderS opened this issue May 3, 2011 · 3 comments
Closed

nvm does not work, if CDPATH is set #32

AlexanderS opened this issue May 3, 2011 · 3 comments

Comments

@AlexanderS
Copy link

Hi,
I noticed that nvm is not working if CDPATH is set in the environment. If set, all cd commands echo the entered directory. With that, nvm fails to execute necessary commands.

Here is a patch, that fixes this issue:

diff --git a/nvm.sh b/nvm.sh
index 6f107ec..42a3653 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -7,7 +7,7 @@

 # Auto detect the NVM_DIR
 if [ ! -d "$NVM_DIR" ]; then
-    export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}); pwd)
+    export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null; pwd)
 fi

 # Emulate curl with wget, if necessary
@@ -52,17 +52,17 @@ nvm_version()
         PATTERN='*.*.'
     fi
     if [ "$PATTERN" = 'all' ]; then
-        (cd $NVM_DIR; ls -dG v* 2>/dev/null || echo "N/A")
+        (cd $NVM_DIR > /dev/null; ls -dG v* 2>/dev/null || echo "N/A")
         return
     fi
     if [ ! "$VERSION" ]; then
-        VERSION=`(cd $NVM_DIR; ls -d v${PATTERN}* 2>/dev/null) | sort -t. -k 2,1n -k 2,2n -k 3,3n | tail -n1`
+        VERSION=`(cd $NVM_DIR > /dev/null; ls -d v${PATTERN}* 2>/dev/null) | sort -t. -k 2,1n -k 2,2n -k 3,3n | tail -n1`
     fi
     if [ ! "$VERSION" ]; then
         echo "N/A"
         return 13
     elif [ -e "$NVM_DIR/$VERSION" ]; then
-        (cd $NVM_DIR; ls -dG "$VERSION")
+        (cd $NVM_DIR > /dev/null; ls -dG "$VERSION")
     else
         echo "$VERSION"
     fi
@@ -181,7 +181,7 @@ nvm()
     "alias" )
       mkdir -p $NVM_DIR/alias
       if [ $# -le 2 ]; then
-        (cd $NVM_DIR/alias && for ALIAS in `ls $2* 2>/dev/null`; do
+        (cd $NVM_DIR/alias > /dev/null && for ALIAS in `ls $2* 2>/dev/null`; do
             DEST=`cat $ALIAS`
             VERSION=`nvm_version $DEST`
             if [ "$DEST" = "$VERSION" ]; then
@@ -214,7 +214,7 @@ nvm()
         [ "$NOCURL" ] && curl && return
         LATEST=`nvm_version latest`
         STABLE=`nvm_version stable`
-        (cd $NVM_DIR
+        (cd $NVM_DIR > /dev/null
         rm -f v* 2>/dev/null
         printf "# syncing with nodejs.org..."
         for VER in `curl -s http://nodejs.org/dist/ -o - | grep 'node-v.*\.tar\.gz' | sed -e 's/.*node-//' -e 's/\.tar\.gz.*//'`; do

Thanks,
Alex

@AlexanderS
Copy link
Author

Note: I also added a pull request with this patch.

@AlexanderS AlexanderS reopened this May 3, 2011
@trappist
Copy link

trappist commented Jul 7, 2011

+1, I ran into this.

@ljharb
Copy link
Member

ljharb commented Feb 16, 2014

Fixed by 42915fc

@ljharb ljharb closed this as completed Feb 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants