aboutsummaryrefslogtreecommitdiffstats
path: root/src/_yarn
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2019-10-02 07:42:15 -0700
committerMaxim Devoir <maximdevoir@gmail.com>2019-10-02 07:42:15 -0700
commita47b58ef97ad489f19fc1ecb9933597eef9a927a (patch)
treeb167564ea741edc725989405125216e84d547059 /src/_yarn
parentSeparate project scripts from binary packages (diff)
downloadzsh-completions-a47b58ef97ad489f19fc1ecb9933597eef9a927a.tar
zsh-completions-a47b58ef97ad489f19fc1ecb9933597eef9a927a.tar.gz
zsh-completions-a47b58ef97ad489f19fc1ecb9933597eef9a927a.tar.bz2
zsh-completions-a47b58ef97ad489f19fc1ecb9933597eef9a927a.tar.lz
zsh-completions-a47b58ef97ad489f19fc1ecb9933597eef9a927a.tar.xz
zsh-completions-a47b58ef97ad489f19fc1ecb9933597eef9a927a.tar.zst
zsh-completions-a47b58ef97ad489f19fc1ecb9933597eef9a927a.zip
Parse script commands without `jq`
Source from https://github.com/robbyrussell/oh-my-zsh/pull/8118#issuecomment-537484017
Diffstat (limited to 'src/_yarn')
-rw-r--r--src/_yarn34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/_yarn b/src/_yarn
index e99accf..b50ad7f 100644
--- a/src/_yarn
+++ b/src/_yarn
@@ -81,29 +81,21 @@ _yarn_commands_scripts() {
}
_yarn_scripts() {
- local -a commands
- local -a binaries
- local -a scripts
- local -a scriptsUnescaped
-
- binaries=($(yarn run --json 2>/dev/null | sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n' | sed -e 's/:/\\:/g'))
- scriptsUnescaped=($(yarn run --json 2>/dev/null | sed -E '/possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n'))
- scripts=($(echo "${scriptsUnescaped[@]}" | sed -e 's/:/\\:/g'))
- scriptsObject=$(yarn run --json 2>/dev/null | sed -n '/.type.\s\?:\s\?.possibleCommands./p' | head -1)
+ local -a commands binaries scripts
+ local -a scriptNames scriptCommands
+ local i runJSON
+
+ runJSON=$(yarn run --json 2>/dev/null)
+ binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
+ scriptNames=($(sed -E '/possibleCommands/!d;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
+ scriptCommands=("${(@f)$(sed -E '/possibleCommands/!d;s/.*"hints":\{([^}]+)\}.*/\1/;s/"[^"]+"://g;s/:/\\:/g;s/","/\n/g;s/(^"|"$)//g' <<< "$runJSON")}")
- if [ "$(command -v jq)" ]; then
- for script in "${scriptsUnescaped[@]}"; do
- scriptCommand=$(echo -E $scriptsObject | jq ".data.hints.\"$script\"")
- commands+=("$(echo "${script//:/\\:}"):$scriptCommand")
- done
- else
- for script in "${scripts[@]}"; do
- commands+=("$script:package\.json")
- done
- fi
+ for (( i=1; i <= $#scriptNames; i++ )); do
+ scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
+ done
- commands=("${commands[@]}" "${binaries[@]}")
- _describe 'scripts' commands
+ commands=($scripts $binaries)
+ _describe 'command' commands
}
_yarn_global_commands() {