Colored Pacman output

From ArchWiki
Revision as of 15:39, 27 October 2005 by
Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n links end

Colorizing the output of pacman

Now that makepkg has colorized output, why not pacman as well? Gentoo's package manager application named 'emerge' uses colors extensively, and as you can see in this screenshot, it greatly enhances readability.


User citral uses the following script in his .bashrc:

alias pacs="pacsearch"
pacsearch () {
       echo -e "$(pacman -Ss $@ | sed \
       -e 's#current/.*#\\033[1;31m&\\033[0;37m#g' \
       -e 's#extra/.*#\\033[0;32m&\\033[0;37m#g' \
       -e 's#community/.*#\\033[1;35m&\\033[0;37m#g' \
       -e 's#^.*/.* [0-9].*#\\033[0;36m&\\033[0;37m#g' )"

Using 'acoc'

There is another, more general possibility of colorizing arbitrary command output. You can download the small Ruby tool acoc (and its requirements, term-ansicolor and tpty. ). tpty is not really required, but some applications like "ls" won't run with acoc otherwise (they need to be started in a pseudo terminal, or else they behave differently).

Installation is relatively straightforward, here's a quick walkthrough:

$ tar xvzf tpty-0.0.1.tar.gz
$ cd tpty-0.0.1
$ ruby extconf.rb
$ make
$ ruby ./test.rb
# make install
$ tar xvzf term-ansicolor-1.0.1.tar.gz
$ cd term-ansicolor-1.0.1
# ruby install.rb

And now acoc itself:

$ tar xvzf acoc-0.7.1.tar.gz
$ cd acoc-0.7.1
# make install

Now, just read the section "Advanced Installation" in acoc's INSTALL file, and configure acoc as you want to. Create a link for 'pacman' as well, since that's primarily what we're doing this for. Once acoc runs, you can add these lines to your acoc.conf:

[pacman -Si]
/^Name\s+:\s([\w.-]+)/                              bold
[pacman -Qi]
/^Name\s+:\s([\w.-]+)/                              bold
[pacman -Qi$]
/^([\w.-]+)\s([\w.-]+)/                 bold,clear
[pacman -Ss]
/^([\w.-]+)\/([\w.-]+)\s+([\w.-]+)/     clear,bold,clear
[pacman -Qs]
/^([\w.-]+)\/([\w.-]+)\s+([\w.-]+)/     clear,bold,clear
[pacman -Sl]
/^([\w.-]+)\s([\w.-]+)\s([\w.-]+)/              clear,bold,clear
[pacman -Qo]
/^([\w.-\/]+)\sis\sowned\sby\s([\w.-]+)\s([\w.-]+)/     clear,bold,clear
[pacman -Qe$]
/^([\w.-]+)\s([\w.-]+)/                 bold,clear
[pacman -Qg$]
/^([\w.-]+)\s([\w.-]+)/                 clear,bold

It might not be perfect, or particularly nice, but so far it works fine for me. The above lines just make pacman print all package names in bold, which is particularly helpful when doing e.g. "pacman -Ss xfce". If you like it more colorful, you can modify the lines as you want. Read the acoc documentation contained in the source package for more information.


Forum thread