[arch-general] script to reformat 'pacman -Ss' output into 2 readable columns (prevents blindness)
Dave Reisner
d at falconindy.com
Fri Aug 6 01:33:27 EDT 2010
On Thu, Aug 05, 2010 at 10:51:45PM -0500, David C. Rankin wrote:
> Guys,
>
> I developed a script...
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
More information about the arch-general
mailing list