On 06/08/10 06:33, Dave Reisner wrote:
Hi.
Let's see what we can do about cutting back a little on the verbosity, and upping the utility...
-------------------------
#!/bin/bash
pkg=() desc=() count=-1 WIDTH=${WIDTH:-50}
while read line; do if [[ $line =~ ^(testing|core|extra|community|community-testing)/* ]]; then (( count++ )) pkg[count]="$line" continue fi
desc[count]+="$line" done
i=0 while (( i<= count )); do IFS=$'\n' read -r -d'\0' -a blockdesc< <(fmt -w$WIDTH<<< "${desc[i]}")
paste -d' '<(printf "%-49s" "${pkg[i]}")<(echo "${blockdesc[0]}")
for line in "${blockdesc[@]:1}"; do printf "%-50s%s\n" "" "$line" done
(( ++i )) [[ $1 == -d ]]&& echo done
-------------------------
It takes STDIN, and accepts a -d option to add a space after each package. Descriptions have a default width of 50 characters (meaning a total width of 100 characters). You can alter this by specifying WIDTH as an environment var, e.g.
$ pacman -Ss | WIDTH=30 ./foofilter -d
Personally I think pacman-color is a better solution that mangling the output like this, but to each their own.
d
--- Thanks for this one, I've messed around with it a little and it's a handy little function for searching.