In addition to ArchLinux - yaourt: save updatelog?

With tee I am able to get the output at a file and at the terminal at the same time. But when I execute yaourt -Syu | tee yaourt.log in a bash file (which is executed in a terminal) the output of yaourt does not have the usual colors (no colors). Also (sure) when opening the text file you cannot see colors.

  • Is it possible to still see the color formatting of yaourt when executing the above command via a bash script?
  • Is it possible to see the saved text in the same color formatting later again?
link|improve this question

20% accept rate
feedback

1 Answer

The yaourt script disables colours if it detects that the output is not going to a terminal. Comment out that line and you will have colours everywhere.

236 # Disable color if output is not a terminal
237 [[ -t 1 ]] || { USECOLOR=0; TERMINALTITLE=0; }

Why it does this because if you view the file it puts in a lot of unprintable characters.

For example

$ echo -e '\e[1;33mBanana\e[;m' |tee /tmp/colour_test
Banana

What this looks like in VIM:

^[[1;33mBanana^[[;m

For yaourt output it is a LOT worse.

link|improve this answer
Thanks! But: - Where to comment the line out? - When the file is created with these unprintable characters, does that mean it looks like in the terminal when opened in vim? Can I create two files, one color-formatted and a plain one with text only without big effort? – user905686 Jan 26 at 18:26
The comment needs to be applied in yaourt. yaourt is just a shell script. If you comment out the line it will print the special characters to the file but when you use cat or similar it will translate it to colours. It is only when you start using a text editor is when you will see the special characters. You could edit yaourt to write to a file, one in colour and the other not. Alternately you could try something silly like: – DarkHeart Jan 28 at 5:20
yaort -Sayu 2>&1 | tee colour.out|perl -pe 's/^[\d*\;\d*m//g;s/^[[\d*\;\d*m//g;' | tee plain.out – DarkHeart Jan 28 at 5:32
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.