From d9c58d5fa10a1e9911d61adf7ccfbd64b24e713f Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Thu, 3 Feb 2022 14:42:47 +0100 Subject: [PATCH] feat(yarn): add setting to disable adding global dir to `$PATH` (#10642) --- plugins/yarn/README.md | 9 +++++++++ plugins/yarn/yarn.plugin.zsh | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/plugins/yarn/README.md b/plugins/yarn/README.md index 9a0d1708d..9c16ff2c3 100644 --- a/plugins/yarn/README.md +++ b/plugins/yarn/README.md @@ -9,6 +9,15 @@ To use it, add `yarn` to the plugins array in your zshrc file: plugins=(... yarn) ``` +## Global scripts directory + +It also adds `yarn` global scripts dir (commonly `~/.yarn/bin`) to the `$PATH`. +To disable this feature, set the following style in your `.zshrc`: + +```zsh +zstyle ':omz:plugins:yarn' global-path false +``` + ## Aliases | Alias | Command | Description | diff --git a/plugins/yarn/yarn.plugin.zsh b/plugins/yarn/yarn.plugin.zsh index 9ba24420a..bcb8661cf 100644 --- a/plugins/yarn/yarn.plugin.zsh +++ b/plugins/yarn/yarn.plugin.zsh @@ -1,12 +1,14 @@ -# Skip yarn call if default global bin dir exists -[[ -d "$HOME/.yarn/bin" ]] && bindir="$HOME/.yarn/bin" || bindir="$(yarn global bin 2>/dev/null)" +if zstyle -T ':omz:plugins:yarn' global-path; then + # Skip yarn call if default global bin dir exists + [[ -d "$HOME/.yarn/bin" ]] && bindir="$HOME/.yarn/bin" || bindir="$(yarn global bin 2>/dev/null)" -# Add yarn bin directory to $PATH if it exists and not already in $PATH -[[ $? -eq 0 ]] \ - && [[ -d "$bindir" ]] \ - && (( ! ${path[(Ie)$bindir]} )) \ - && path+=("$bindir") -unset bindir + # Add yarn bin directory to $PATH if it exists and not already in $PATH + [[ $? -eq 0 ]] \ + && [[ -d "$bindir" ]] \ + && (( ! ${path[(Ie)$bindir]} )) \ + && path+=("$bindir") + unset bindir +fi alias y="yarn" alias ya="yarn add"