From 45bc358892a479a56cb1fdfcd00d884e2badd824 Mon Sep 17 00:00:00 2001 From: Shahar Date: Wed, 8 Jul 2015 03:42:57 +0300 Subject: [PATCH 1/5] Adds a node_modules-bin plugin --- .../node_modules-bin.plugin.zsh | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 plugins/node_modules-bin/node_modules-bin.plugin.zsh diff --git a/plugins/node_modules-bin/node_modules-bin.plugin.zsh b/plugins/node_modules-bin/node_modules-bin.plugin.zsh new file mode 100644 index 000000000..7e9c75993 --- /dev/null +++ b/plugins/node_modules-bin/node_modules-bin.plugin.zsh @@ -0,0 +1,33 @@ +zsh-node_modules-bin-update-path() { + if [[ ! -x $(which npm) ]]; then + # there is no npm + return + fi + + # figure out the path + NPM_BIN_PATH=$(npm bin) + + if [[ ! -d $NPM_BIN_PATH ]]; then + # there is no dir at bin path + return + fi + + if [[ -n $OLD_NPM_BIN_PATH && $NPM_BIN_PATH == $OLD_NPM_BIN_PATH ]]; then + # bin path did not change + return + fi + + if [[ -n $OLD_NPM_BIN_PATH ]]; then + # remove old bin path from $path + path[$path[(i)$OLD_NPM_BIN_PATH]]=() + fi + + # add new bin path to $path + path=($NPM_BIN_PATH $path) + export PATH + + # for next run + export OLD_NPM_BIN_PATH=$NPM_BIN_PATH +} + +precmd_functions+="zsh-node_modules-bin-update-path" From 8f4c80385d08d8bc5ace83d84181c3c6348fb2aa Mon Sep 17 00:00:00 2001 From: Shahar Date: Wed, 8 Jul 2015 06:13:11 +0300 Subject: [PATCH 2/5] node_modules-bin module: no need to export that var --- plugins/node_modules-bin/node_modules-bin.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/node_modules-bin/node_modules-bin.plugin.zsh b/plugins/node_modules-bin/node_modules-bin.plugin.zsh index 7e9c75993..2b8280b00 100644 --- a/plugins/node_modules-bin/node_modules-bin.plugin.zsh +++ b/plugins/node_modules-bin/node_modules-bin.plugin.zsh @@ -27,7 +27,7 @@ zsh-node_modules-bin-update-path() { export PATH # for next run - export OLD_NPM_BIN_PATH=$NPM_BIN_PATH + OLD_NPM_BIN_PATH=$NPM_BIN_PATH } precmd_functions+="zsh-node_modules-bin-update-path" From 9157b7c7de918cd87a9f3817b63b814b34e92373 Mon Sep 17 00:00:00 2001 From: Shahar Date: Fri, 10 Jul 2015 04:52:11 +0300 Subject: [PATCH 3/5] Renamed node_modules-bin module to npm-path Now uses npm-path instead of very slow `npm bin` --- .../node_modules-bin.plugin.zsh | 33 ------------------- plugins/npm-path/npm-path.plugin.zsh | 15 +++++++++ 2 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 plugins/node_modules-bin/node_modules-bin.plugin.zsh create mode 100644 plugins/npm-path/npm-path.plugin.zsh diff --git a/plugins/node_modules-bin/node_modules-bin.plugin.zsh b/plugins/node_modules-bin/node_modules-bin.plugin.zsh deleted file mode 100644 index 2b8280b00..000000000 --- a/plugins/node_modules-bin/node_modules-bin.plugin.zsh +++ /dev/null @@ -1,33 +0,0 @@ -zsh-node_modules-bin-update-path() { - if [[ ! -x $(which npm) ]]; then - # there is no npm - return - fi - - # figure out the path - NPM_BIN_PATH=$(npm bin) - - if [[ ! -d $NPM_BIN_PATH ]]; then - # there is no dir at bin path - return - fi - - if [[ -n $OLD_NPM_BIN_PATH && $NPM_BIN_PATH == $OLD_NPM_BIN_PATH ]]; then - # bin path did not change - return - fi - - if [[ -n $OLD_NPM_BIN_PATH ]]; then - # remove old bin path from $path - path[$path[(i)$OLD_NPM_BIN_PATH]]=() - fi - - # add new bin path to $path - path=($NPM_BIN_PATH $path) - export PATH - - # for next run - OLD_NPM_BIN_PATH=$NPM_BIN_PATH -} - -precmd_functions+="zsh-node_modules-bin-update-path" diff --git a/plugins/npm-path/npm-path.plugin.zsh b/plugins/npm-path/npm-path.plugin.zsh new file mode 100644 index 000000000..e9945e513 --- /dev/null +++ b/plugins/npm-path/npm-path.plugin.zsh @@ -0,0 +1,15 @@ +zsh-node_modules-bin-update-path() { + if [[ ! -x $(which npm) ]]; then + # there is no npm + return + fi + + if [[ ! -r $(which npm-path) ]]; then + echo "npm-path must be available for the oh-my-zshell npm-path module to update your PATH" + return + fi + + export PATH=$(npm-path) +} + +precmd_functions+="zsh-node_modules-bin-update-path" From 1227e7145dece73cdc00d589550ac4c33bd908a3 Mon Sep 17 00:00:00 2001 From: Shahar Date: Fri, 10 Jul 2015 04:58:47 +0300 Subject: [PATCH 4/5] npm-path module: better warning message --- plugins/npm-path/npm-path.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/npm-path/npm-path.plugin.zsh b/plugins/npm-path/npm-path.plugin.zsh index e9945e513..90047d784 100644 --- a/plugins/npm-path/npm-path.plugin.zsh +++ b/plugins/npm-path/npm-path.plugin.zsh @@ -5,7 +5,7 @@ zsh-node_modules-bin-update-path() { fi if [[ ! -r $(which npm-path) ]]; then - echo "npm-path must be available for the oh-my-zshell npm-path module to update your PATH" + echo "WARNING: npm-path must be available for the oh-my-zshell npm-path module to update your PATH. Perhaps \`npm --global install npm-path\` will help." return fi From 71700cdd1c2f9d7bd994d11d6b1b3265689ea91a Mon Sep 17 00:00:00 2001 From: Shahar Date: Fri, 10 Jul 2015 05:01:01 +0300 Subject: [PATCH 5/5] npm-path module: fixed function name --- plugins/npm-path/npm-path.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/npm-path/npm-path.plugin.zsh b/plugins/npm-path/npm-path.plugin.zsh index 90047d784..1b74fb5e7 100644 --- a/plugins/npm-path/npm-path.plugin.zsh +++ b/plugins/npm-path/npm-path.plugin.zsh @@ -1,4 +1,4 @@ -zsh-node_modules-bin-update-path() { +zsh-npm-path() { if [[ ! -x $(which npm) ]]; then # there is no npm return @@ -12,4 +12,4 @@ zsh-node_modules-bin-update-path() { export PATH=$(npm-path) } -precmd_functions+="zsh-node_modules-bin-update-path" +precmd_functions+="zsh-npm-path"