Compare commits

...

2 commits

Author SHA1 Message Date
Shy
39323d772a Fixed regex for preset name matching. 2024-08-06 11:00:10 +02:00
Shy
24b3b8c945 Simplified active_preset(). 2024-08-06 10:56:01 +02:00

7
wled
View file

@ -38,10 +38,9 @@ curl_cmd() {
active_preset() {
# Find number of active preset. API returns -1 if none is active, we return
# an empty string.
preset="$(curl_cmd "http://$1/json" | \
curl_cmd "http://$1/json" | \
# -1 will be a no-match.
sed -n 's/.*"ps"[[:space:]]*:[[:space:]]*\(1\?[0-9]\).*/\1/p')"
printf '%u' "$preset"
sed -n 's/.*"ps"[[:space:]]*:[[:space:]]*\(1\?[0-9]\).*/\1/p'
}
# Parse host argument.
@ -103,7 +102,7 @@ case "$2" in
# Extract number and name of every preset. Right-align numbers.
# Drop everything else.
sed --sandbox -n \
'/^"\(1\?[0-9]\)"[[:space:]]*:.*"n"[[:space:]]*:[[:space:]]*"\([[:print:]]*\)".*$/{
'/^"\(1\?[0-9]\)"[[:space:]]*:.*"n"[[:space:]]*:[[:space:]]*"\([[:alnum:] _-]*\)".*$/{
s//\1: \2/
s/^[0-9]:/ &/
p