Yarn | cross-platform sed replacement pattern newline solution (#666)

Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement pattern as a newline.
This commit is contained in:
Maxim Devoir 2020-01-17 13:22:00 -08:00 committed by GitHub
parent e32536a208
commit 493984e7f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -86,9 +86,11 @@ _yarn_scripts() {
local i runJSON local i runJSON
runJSON=$(yarn run --json 2>/dev/null) 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")) # Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement
scriptNames=($(sed -E '/possibleCommands/!d;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g;s/:/\\:/g;s/,/\n/g' <<< "$runJSON")) # pattern as a newline. See https://superuser.com/q/307165
scriptCommands=("${(@f)$(sed -E '/possibleCommands/!d;s/.*"hints":\{(.+")\}.*/\1/;s/"[^"]+"://g;s/:/\\:/g;s/","/\n/g;s/(^"|"$)//g' <<< "$runJSON")}") 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")}")
for (( i=1; i <= $#scriptNames; i++ )); do for (( i=1; i <= $#scriptNames; i++ )); do
scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}") scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")