Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

An easier way to display the color formatting of yaourt in the terminal and to save the output (with color codes) at the same time in a file is to use the yaourt color option :

yaourt -Syua --color | tee yaourt.log  

To display the log file use :

cat yaourt.log  

instead of a text editor, because the color codes make the log unreadable

share|improve this answer
    
Great, that works! –  user905686 Jan 18 '13 at 13:06
add comment

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.

share|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 '12 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 '12 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 '12 at 5:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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