From 45bc358892a479a56cb1fdfcd00d884e2badd824 Mon Sep 17 00:00:00 2001 From: Shahar Date: Wed, 8 Jul 2015 03:42:57 +0300 Subject: [PATCH] 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"