Parse script commands without `jq`
Source from https://github.com/robbyrussell/oh-my-zsh/pull/8118#issuecomment-537484017
This commit is contained in:
parent
c6bdbc69e1
commit
a47b58ef97
34
src/_yarn
34
src/_yarn
|
@ -81,29 +81,21 @@ _yarn_commands_scripts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_yarn_scripts() {
|
_yarn_scripts() {
|
||||||
local -a commands
|
local -a commands binaries scripts
|
||||||
local -a binaries
|
local -a scriptNames scriptCommands
|
||||||
local -a scripts
|
local i runJSON
|
||||||
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)
|
|
||||||
|
|
||||||
if [ "$(command -v jq)" ]; then
|
runJSON=$(yarn run --json 2>/dev/null)
|
||||||
for script in "${scriptsUnescaped[@]}"; do
|
binaries=($(sed -E '/Commands available/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
|
||||||
scriptCommand=$(echo -E $scriptsObject | jq ".data.hints.\"$script\"")
|
scriptNames=($(sed -E '/possibleCommands/!d;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON"))
|
||||||
commands+=("$(echo "${script//:/\\:}"):$scriptCommand")
|
scriptCommands=("${(@f)$(sed -E '/possibleCommands/!d;s/.*"hints":\{([^}]+)\}.*/\1/;s/"[^"]+"://g;s/:/\\:/g;s/","/\n/g;s/(^"|"$)//g' <<< "$runJSON")}")
|
||||||
done
|
|
||||||
else
|
|
||||||
for script in "${scripts[@]}"; do
|
|
||||||
commands+=("$script:package\.json")
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
commands=("${commands[@]}" "${binaries[@]}")
|
for (( i=1; i <= $#scriptNames; i++ )); do
|
||||||
_describe 'scripts' commands
|
scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")
|
||||||
|
done
|
||||||
|
|
||||||
|
commands=($scripts $binaries)
|
||||||
|
_describe 'command' commands
|
||||||
}
|
}
|
||||||
|
|
||||||
_yarn_global_commands() {
|
_yarn_global_commands() {
|
||||||
|
|
Loading…
Reference in New Issue