From 2c19349a09e8b0752d60ad5eb1ac30a83fd341f4 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 22 May 2020 14:00:38 +0300 Subject: [PATCH] kiss: Remove need for external sort of extension list --- kiss | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kiss b/kiss index 5634991..f4be842 100755 --- a/kiss +++ b/kiss @@ -1475,14 +1475,25 @@ args() { # see [1] at top of script. set -- $(KISS_PATH=$PATH pkg_find kiss-\* all -x) - for path do - p=${path#*/kiss-} max=$((${#p} > max ? ${#p}+1 : max)) + # To align descriptions figure out which extension has the longest + # name by doing a simple 'name > max ? name : max' on the basename + # of the path with 'kiss-' stripped as well. + # + # This also removes any duplicates found in '$PATH', picking the + # first match. + for path do p=${path#*/kiss-} + case " $seen " in + *" $p "*) shift ;; + *) seen=" $seen $p " max=$((${#p} > max ? ${#p}+1 : max)) + esac done + # Print each extension, grab its description from the second line + # in the file and align the output based on the above max. for path do printf "%b->%b %-${max}s " "$lcol" "$lclr" "${path#*/kiss-}" sed -n 's/^# *//;2p' "$path" - done | sort -uk1 >&2 + done >&2 ;; *)