From e431d619b0bd9f539ca13108ee675063120c31a3 Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Sun, 11 Feb 2018 11:40:28 -0600 Subject: [PATCH 1/2] (!! fix) Fix NODENV_ROOT handling This plugin previously assumed that `nodenv` used $NODENV_ROOT to store the directory where *nodenv* was installed. This is not the case. This fix uses whichever directory `nodenv` is installing Node.js versions in (preferring the user-local `~/.nodenv/versions` over the system-global one.) --- nodenv.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodenv.plugin.zsh b/nodenv.plugin.zsh index b7c1a9b..e64bb15 100644 --- a/nodenv.plugin.zsh +++ b/nodenv.plugin.zsh @@ -2,7 +2,7 @@ FOUND_NODENV=0 nodenvdirs=("$HOME/.nodenv" "/usr/local/opt/nodenv" "/usr/local/nodenv" "/opt/nodenv") for nodenvdir in "${nodenvdirs[@]}" ; do - if [ -d $nodenvdir/bin -a $FOUND_NODENV -eq 0 ] ; then + if [ -d $nodenvdir/versions -a $FOUND_NODENV -eq 0 ] ; then FOUND_NODENV=1 if [[ $NODENV_ROOT = '' ]]; then NODENV_ROOT=$nodenvdir From 3f7ed611b11c5318e526e03e4afe3de391d931ed Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Sun, 11 Feb 2018 11:49:06 -0600 Subject: [PATCH 2/2] (!! fix) Repair space-handling throughout the script Critically, previous versions would fuck up the user's `$PATH` if it happened to include spaces. Unacceptable, yikes. I also refactored the script slightly, to use consistent POSIX tests, consistent casing for variable-names, etceteras. --- nodenv.plugin.zsh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/nodenv.plugin.zsh b/nodenv.plugin.zsh index e64bb15..4249a3b 100644 --- a/nodenv.plugin.zsh +++ b/nodenv.plugin.zsh @@ -1,14 +1,14 @@ -FOUND_NODENV=0 +found_nodenv='' nodenvdirs=("$HOME/.nodenv" "/usr/local/opt/nodenv" "/usr/local/nodenv" "/opt/nodenv") for nodenvdir in "${nodenvdirs[@]}" ; do - if [ -d $nodenvdir/versions -a $FOUND_NODENV -eq 0 ] ; then - FOUND_NODENV=1 - if [[ $NODENV_ROOT = '' ]]; then - NODENV_ROOT=$nodenvdir + if [ -z "$found_nodenv" ] && [ -d "$nodenvdir/versions" ]; then + found_nodenv=true + if [ -z "$NODENV_ROOT" ]; then + NODENV_ROOT="$nodenvdir" + export NODENV_ROOT fi - export NODENV_ROOT - export PATH=${nodenvdir}/bin:$PATH + export PATH="${nodenvdir}/bin:$PATH" eval "$(nodenv init --no-rehash -)" function current_node() { @@ -22,6 +22,8 @@ for nodenvdir in "${nodenvdirs[@]}" ; do done unset nodenvdir -if [ $FOUND_NODENV -eq 0 ] ; then - function nodenv_prompt_info() { echo "system: $(node --version)" } +if [ -z "$found_nodenv" ]; then + function nodenv_prompt_info() { + echo "system: $(node --version)" + } fi