From 4111037d4c2e0c06f5410df4ba2b937f891ae2e1 Mon Sep 17 00:00:00 2001 From: Shy Date: Mon, 5 Aug 2024 15:51:46 +0200 Subject: [PATCH] Revised regular expressions. --- wled | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wled b/wled index 344f299..49aff8e 100755 --- a/wled +++ b/wled @@ -86,12 +86,14 @@ case "$2" in api_resp=$(curl_cmd --json "{'ps':$2}" "http://$wled_host/json") ;; l|list) # List presets. - echo "Presets on $wled_host:" + printf "loading ...\r" curl_cmd "http://$wled_host/presets.json" | \ # Split into lines - one line per preset. Append final newline. - sed --sandbox 's/"\(1\?[0-9]\)"/\n"\1"/g; $a\ ' | \ - # Extract number and name of every preset. - sed --sandbox -n 's/^"\(1\?[0-9]\)":.*"n":"\([[:print:]]*\)".*$/\1: \2/p' + sed --sandbox 's/"\(1\?[0-9]\)"[[:space:]]*:/\n&/g; $a\ ' | \ + # Extract number and name of every preset. Prepend description. + sed --sandbox -n \ + -e 's/^"\(1\?[0-9]\)"[[:space:]]*:.*"n"[[:space:]]*:[[:space:]]*"\([[:print:]]*\)".*$/\1: \2/p' \ + -e "1i\\Presets on $wled_host:" exit $? ;; dump) # Dump JSON response from API. @@ -118,7 +120,7 @@ if test $curl_exit -ne 0; then fi # Check API responce. -if test "$api_resp" != '{"success":true}'; then +if echo "$api_resp" | grep -qv '{\s*"success"\s*:\s*true\s*}'; then echo "Error: unexpected responce from WLED API." >&2 exit 1 fi