Revised regular expressions.

This commit is contained in:
Shy 2024-08-05 15:51:46 +02:00
parent 1f825347ab
commit 4111037d4c

12
wled
View file

@ -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