Sort list of presets.

This commit is contained in:
Shy 2024-08-05 19:19:30 +02:00
parent 80d5972f80
commit 4bdafb7f2e

8
wled
View file

@ -98,8 +98,8 @@ case "$2" in
printf "loading ...\r"
active_ps=$(active_preset "$wled_host")
curl_cmd "http://$wled_host/presets.json" | \
# Split into lines - one line per preset. Append final newline.
sed --sandbox 's/"\(1\?[0-9]\)"[[:space:]]*:/\n&/g; $a\ ' | \
# Split into lines - one line per preset.
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \
# Prepend description, extract number and name of every preset,
# match active preset, right-align numbers and finally select
# lines to print.
@ -108,7 +108,9 @@ case "$2" in
-e 's/^"\(1\?[0-9]\)"[[:space:]]*:.*"n"[[:space:]]*:[[:space:]]*"\([[:print:]]*\)".*$/\1: \2/' \
-e "s/^$active_ps:.*/& */" \
-e 's/^[0-9]:/ &/' \
-e '/^[1 ]\?[0-9]: [[:print:]]\+/p'
-e '/^[1 ]\?[0-9]: [[:print:]]\+/p' | \
# Sort.
sort -b -n
exit $?
;;
dump) # Dump JSON response from API.