diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2022-02-19 17:12:23 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2022-02-19 17:12:23 -0600 |
commit | cae9a2b797649379e865e6bd73bc67e294e4ac77 (patch) | |
tree | 481419eff4bc761c3ca516704427394193473419 /plugins/yarn | |
parent | 49edbf438ed690c76e6b2af80368c59404cf0167 (diff) | |
parent | 3427da4057dbe302933a7b5b19b4e23bfb9d0969 (diff) | |
download | zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.tar.gz zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.tar.bz2 zsh-cae9a2b797649379e865e6bd73bc67e294e4ac77.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'plugins/yarn')
-rw-r--r-- | plugins/yarn/README.md | 9 | ||||
-rw-r--r-- | plugins/yarn/_yarn | 4 | ||||
-rw-r--r-- | plugins/yarn/yarn.plugin.zsh | 18 |
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" |