2

When I use:

msgattrib --untranslated pl.po

to see untranslated strings from po file I've got strings in color, but not when I use:

msgattrib --untranslated pl.po | less
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
jcubic
  • 9,932

3 Answers3

8

msgattrib display colors only if executed from real terminal. You can use unbuffer command that's part of expect to make msgattrib think that it's executed from real terminal and then use -r option to handle ANSI escapes in less:

unbuffer msgattrib --untranslated pl.po | less -r

You can do that in any command that produce colors (ANSI escapes codes) based on existance of tty.

jcubic
  • 9,932
1

From the less man page:

-R or --RAW-CONTROL-CHARS
          Like -r, but only ANSI "color" escape sequences are output in "raw" form.  Unlike -r, the screen appearance is maintained correctly in most  cases.

The simplest way to have this enabled all the time is to set the LESS environment variable in your .profile or .login script. I use both -R and -X (which prevents the screen being cleared when less exits).

rdanter
  • 111
  • 2
    This don't change behavior of msgattrib that will not produce the colors if you pipe to less, -R will not change anything because there will be no escapes codes. – jcubic Mar 03 '20 at 20:57
  • @jcubic's comment here is correct, but this answer does provide that you won't need the -r or -R flag when piping output from unbuffer as in @jcubic's answer. – mc0e Sep 03 '23 at 05:17
1

To show less with colors: less -R <text-file> Or config your less as an alias like alias less='less -R' inside the ~/.bashrc