From 1ad9d18257af5e478a0913897c92da6512873074 Mon Sep 17 00:00:00 2001 From: 00Davo Date: Wed, 18 Sep 2013 17:10:24 +1000 Subject: [PATCH 1/2] Finds NVM_DIR without using cd Using `cd` makes the nvm directory the number-one directory in `autojump`'s database---which is somewhat confusing since the user basically never `cd`s to it directly!---so here's an alternative method that doesn't use the `cd` command. I've checked it works in both Bash and Zsh. --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index aaeb18e..c2d40e2 100755 --- a/nvm.sh +++ b/nvm.sh @@ -9,7 +9,7 @@ # Auto detect the NVM_DIR if [ ! -d "$NVM_DIR" ]; then - export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) + export NVM_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]:-$0})) fi # Make zsh glob matching behave same as bash From a2a8ddb779dd3848d03483ad41441fcead0a0772 Mon Sep 17 00:00:00 2001 From: 00Davo Date: Thu, 19 Sep 2013 02:50:20 +1000 Subject: [PATCH 2/2] Use only shell builtins to avoid triggering autojump, instead of needing GNU readlink Under Zsh, the `-q` flag to `cd` makes it not run `chpwd` hooks and hence makes it not add `~/.nvm` to `autojump`. --- nvm.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nvm.sh b/nvm.sh index c2d40e2..e4ce9f8 100755 --- a/nvm.sh +++ b/nvm.sh @@ -7,15 +7,16 @@ # Implemented by Tim Caswell # with much bash help from Matthew Ranney -# Auto detect the NVM_DIR -if [ ! -d "$NVM_DIR" ]; then - export NVM_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]:-$0})) -fi - # Make zsh glob matching behave same as bash # This fixes the "zsh: no matches found" errors if [ ! -z "$(which unsetopt 2>/dev/null)" ]; then unsetopt nomatch 2>/dev/null + NVM_CD_FLAGS="-q" +fi + +# Auto detect the NVM_DIR +if [ ! -d "$NVM_DIR" ]; then + export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) fi nvm_set_nullglob() {