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