From a03d5d57a044eaf1da57feebf1a89d9d31cbec98 Mon Sep 17 00:00:00 2001 From: Shy Date: Wed, 7 Aug 2024 14:24:06 +0200 Subject: [PATCH] Revised sed script for listing presets. --- wled | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/wled b/wled index c357eb9..405024e 100755 --- a/wled +++ b/wled @@ -136,16 +136,18 @@ for wled_host; do printf "loading ...\r" active_ps=$(active_preset "$wled_host") curl_fetch "http://$wled_host/presets.json" | \ - # 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:] _-]*\)".*$/{ + # Split into lines - one line per preset. Extract number and + # name of every preset. Right-align numbers. + 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/^[0-9]:/ &/ - p - }' | \ + P + } + s/^[^\n]*\n// + t loop' | \ # Sort. sort -b -n | \ # Prepend description and mark active preset.