From e701660ff161385fd63c10a53a168ff5e18c3404 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:21 -0700 Subject: [PATCH] plugins/node: use `_command_exists` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses bash-it/bash-it#1632 alsö, quote variable, use `[[`, &c. --- clean_files.txt | 1 + plugins/available/node.plugin.bash | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8fdc0c10..3f597470 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/node.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 65df3da3..8bf876df 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,13 +1,14 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Node.js helper functions' +# Check that we have npm +_command_exists npm || return + # Ensure local modules are preferred in PATH pathmunge "./node_modules/.bin" "after" -# Check that we have npm -out=$(command -v npm 2>&1) || return - # If not using nodenv, ensure global modules are in PATH -if [[ ! $out == *"nodenv/shims"* ]] ; then - pathmunge "$(npm config get prefix)/bin" "after" +if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then + pathmunge "$(npm config get prefix)/bin" "after" fi