You are not logged in.

#1 2009-03-20 16:45:44

jjt3hii
Member
Registered: 2008-06-09
Posts: 22

color with more, less, tail, head, ect?

Is it possible to have the more, less, tail, or head commands retain the color in the console?  For instance, "pacman-color -Ss kde4 | more" will strip all the colors.  ...or is there an alternative command that I may not know about that retains the colors?

Thanks,

Jason

Offline

#2 2009-03-20 17:02:12

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: color with more, less, tail, head, ect?

As you noticed apps can see if they output to tty or a pipe. I don't know about pacman-color (check its man page), but for ls and grep and such there is --color=always. And then less has -R to interpret it correctly (not sure if it's necessary).

Offline

#3 2009-03-20 17:17:06

plurt
Member
Registered: 2008-10-16
Posts: 88

Re: color with more, less, tail, head, ect?

I'm not sure if it's exactly what you need, but it might be helpfull, check this post:
http://bbs.archlinux.org/viewtopic.php? … 69#p518569


When everything's coming your way, you're in the wrong lane I say.
FAQ / Beginners Guide / The Arch Way

Offline

#4 2009-03-20 21:13:10

quarkup
Member
From: Portugal
Registered: 2008-09-07
Posts: 497
Website

Re: color with more, less, tail, head, ect?

My bash's colors:
-> $PS1 (the prompt)
-> ls
-> grep
-> vi
-> manpages
-> colordiff
-> pacman-color
-> colorgcc

these lines below work for the manpages,  but they do not work on less.
export LESS_TERMCAP_md=$'\e[01;34m';
export LESS_TERMCAP_mb=$'\e[00;34m';
export LESS_TERMCAP_me=$'\e[00;00m';
export LESS_TERMCAP_se=$'\e[00;00m';
export LESS_TERMCAP_so=$'\e[01;31m';
export LESS_TERMCAP_ue=$'\e[00;00m';
export LESS_TERMCAP_us=$'\e[01;32m';

Last edited by quarkup (2009-03-20 21:19:17)


If people do not believe that mathematics is simple, it is only because they do not realize how complicated life is.
Simplicity is the ultimate sophistication.

Offline

#5 2009-03-21 00:25:48

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: color with more, less, tail, head, ect?

Generally you can feed color codes through less -R. However this appears not to work with pacman-color.
This is what I found here (on an xterm).
pacman-color -Ss kde4 produces colored output
pacman-color -Ss kde4 | less -R produces b/w output sad

However:
yaourt -Ss kde4 | less -R produces colored output smile

I do not have the time now to view the pacman-color script. Does anyone know how it does handle colors?

Last edited by bernarcher (2009-03-21 00:26:11)


To know or not to know ...
... the questions remain forever.

Offline

#6 2009-03-21 00:47:48

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: color with more, less, tail, head, ect?

@bernarcher: Or specifically, does an app exist that can fool a program into thinking it is outputting to a tty?

e.g.
ls --color=auto gives color
ls --color=auto | less gives no color
faketty ls --color=auto | less would give color

Last edited by Procyon (2009-03-21 00:48:57)

Offline

#7 2009-03-21 10:45:20

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: color with more, less, tail, head, ect?

Procyon wrote:

faketty ls --color=auto | less would give color

A bit off-topic, but I am completely ignorant of faketty.
It is a kernel module, right? I just can't find suitable info (did some simple google search only).

BTW: ls -l --color=auto works, ls -l --color=auto | less -R does not.
Looks like I am missing some in-depth understanding of how color control works with less. Are there any docs about this topic?


To know or not to know ...
... the questions remain forever.

Offline

#8 2009-03-21 10:50:26

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: color with more, less, tail, head, ect?

No, I was wondering if something exists that could do that, I don't know of any faketty program. Well it's not a big deal of course.

The color control is not about less, but it is ls that knows it is outputting to a pipe, and then decides to strip all colors from output.

Offline

#9 2009-03-21 10:52:58

test1000
Member
Registered: 2005-04-03
Posts: 834

Re: color with more, less, tail, head, ect?

ls --color=auto means: show colors if stdout is a terminal, if the output is(sent into) a pipe, don't use colors.

you have to use the always flag if you always want colors... same behaviour in grep and some other tools too if i recall correctly.

btw, this is in info documentation(for colored info docs, use pinfo). 'pinfo ls'

Last edited by test1000 (2009-03-21 10:57:36)


KISS = "It can scarcely be denied that the supreme goal of all theory is to make the irreducible basic elements as simple and as few as possible without having to surrender the adequate representation of a single datum of experience." - Albert Einstein

Offline

#10 2009-03-21 12:38:14

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: color with more, less, tail, head, ect?

test1000 wrote:

ls --color=auto means: show colors if stdout is a terminal, if the output is(sent into) a pipe, don't use colors.

you have to use the always flag if you always want colors... same behaviour in grep and some other tools too if i recall correctly.

btw, this is in info documentation(for colored info docs, use pinfo). 'pinfo ls'

--color=always This was it!
I always did alias to ls='ls --color=auto', although I should have known better, having read man ls, info ls so many times. sad

When feeding through less, remember to allow raw control codes, though.
ls -l --color=always | less -R
does its coloring job.

Ah, well, another topic to remember firmly. Thanks!

Last edited by bernarcher (2009-03-21 12:39:25)


To know or not to know ...
... the questions remain forever.

Offline

Board footer

Powered by FluxBB