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