Revised list pipeline.

This commit is contained in:
Shy 2024-08-05 19:48:02 +02:00
parent 4bdafb7f2e
commit d08e07fd72

20
wled
View file

@ -100,17 +100,19 @@ case "$2" in
curl_cmd "http://$wled_host/presets.json" | \ curl_cmd "http://$wled_host/presets.json" | \
# Split into lines - one line per preset. # Split into lines - one line per preset.
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \ sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \
# Prepend description, extract number and name of every preset, # Extract number and name of every preset. Right-align numbers.
# match active preset, right-align numbers and finally select # Drop everything else.
# lines to print.
sed --sandbox -n \ sed --sandbox -n \
-e "1i\\Presets on $wled_host:" \ '/^"\(1\?[0-9]\)"[[:space:]]*:.*"n"[[:space:]]*:[[:space:]]*"\([[:print:]]*\)".*$/{
-e 's/^"\(1\?[0-9]\)"[[:space:]]*:.*"n"[[:space:]]*:[[:space:]]*"\([[:print:]]*\)".*$/\1: \2/' \ s//\1: \2/
-e "s/^$active_ps:.*/& */" \ s/^[0-9]:/ &/
-e 's/^[0-9]:/ &/' \ p
-e '/^[1 ]\?[0-9]: [[:print:]]\+/p' | \ }' | \
# Sort. # Sort.
sort -b -n sort -b -n | \
# Prepend description and mark active preset.
sed --sandbox -e "1i\\Presets on $wled_host:" \
-e "s/^ \?$active_ps:.*/& */"
exit $? exit $?
;; ;;
dump) # Dump JSON response from API. dump) # Dump JSON response from API.