summaryrefslogtreecommitdiff
path: root/plugins/yarn
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/yarn')
-rw-r--r--plugins/yarn/README.md9
-rw-r--r--plugins/yarn/_yarn4
-rw-r--r--plugins/yarn/yarn.plugin.zsh18
3 files changed, 21 insertions, 10 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 b/plugins/yarn/_yarn
index 9db02602e..1237ba672 100644
--- a/plugins/yarn/_yarn
+++ b/plugins/yarn/_yarn
@@ -116,7 +116,7 @@ _yarn_commands_scripts() {
fi
if [[ -n $packageJson ]]; then
- scripts=($(cat "$packageJson" | perl -0777 -MJSON::PP -n -E '%r=decode_json($_); say for sort keys %{$r->{scripts}}'))
+ scripts=($(cat "$packageJson" | perl -0777 -MJSON::PP -n -E '$r=decode_json($_); do{($k=$_)=~s/:/\\:/g;say $k}for sort keys %{$r->{scripts}}'))
fi
_describe 'command or script' _commands -- _global_commands -- scripts -- binaries
@@ -144,7 +144,7 @@ _yarn_scripts() {
fi
if [[ -n $packageJson ]]; then
- scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; printf "$_:$r{$_}\n" for sort keys %r')}")
+ scripts=("${(@f)$(cat ${packageJson} | perl -0777 -MJSON::PP -n -E '%r=%{decode_json($_)->{scripts}}; do{$k=$_;($e=$k)=~s/:/\\:/g; printf "$e:$r{$k}\n"} for sort keys %r')}")
fi
commands=('env' $scripts $binaries)
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"