From 493984e7f1a61bb1f345f5261c3dec32502f5b47 Mon Sep 17 00:00:00 2001 From: Maxim Devoir Date: Fri, 17 Jan 2020 13:22:00 -0800 Subject: [PATCH] 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. --- src/_yarn | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/_yarn b/src/_yarn index ce0baef..70e783b 100644 --- a/src/_yarn +++ b/src/_yarn @@ -86,9 +86,11 @@ _yarn_scripts() { 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")}") + # Some sed utilities (e.g. Mac OS / BSD) don't interpret `\n` in a replacement + # pattern as a newline. See https://superuser.com/q/307165 + 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 scripts+=("${scriptNames[$i]}:${scriptCommands[$i]}")