Compare commits

...

2 commits

Author SHA1 Message Date
Shy
eb1e69e05d Revised sed command for listing presets. 2024-08-07 17:19:20 +02:00
Shy
a03d5d57a0 Revised sed script for listing presets. 2024-08-07 14:24:06 +02:00

30
wled
View file

@ -136,21 +136,27 @@ for wled_host; do
printf "loading ...\r" printf "loading ...\r"
active_ps=$(active_preset "$wled_host") active_ps=$(active_preset "$wled_host")
curl_fetch "http://$wled_host/presets.json" | \ curl_fetch "http://$wled_host/presets.json" | \
# Split into lines - one line per preset. # Insert newlines in front of every preset.
sed --sandbox 's/"1\?[0-9]"[[:space:]]*:/\n&/g' | \ # Extract number and name of every preset.
# Extract number and name of every preset. Right-align numbers. # Match and mark active preset.
# Drop everything else. # Right-align numbers.
sed --sandbox -n \ # Print up to next newline, delete up to next newline.
'/^"\(1\?[0-9]\)"[[:space:]]*:.*"n"[[:space:]]*:[[:space:]]*"\([[:alnum:] _-]*\)".*$/{ # Prepend description.
sed --sandbox -n '
s/"1\?[0-9]"[[:space:]]*:/\n&/g
:loop
/^"\(1\?[0-9]\)"[[:space:]]*:[^\n]*"n"[[:space:]]*:[[:space:]]*"\([[:alnum:] _-]*\)"[^\n]*/{
s//\1: \2/ s//\1: \2/
s/^'"$active_ps"':[^\n]*/& */
s/^[0-9]:/ &/ s/^[0-9]:/ &/
p P
}' | \ }
s/^[^\n]*\n//
t loop
i\
'"Presets on $wled_host:" | \
# Sort. # Sort.
sort -b -n | \ sort -n -b -t : -k 1,1
# Prepend description and mark active preset.
sed --sandbox -e "1i\\Presets on $wled_host:" \
-e "s/^ \?$active_ps:.*/& */"
;; ;;
"") # Missing command. "") # Missing command.
echo "Error: missing command." >&2 echo "Error: missing command." >&2