1 |
On Thursday 05 April 2007 20:07, Tony Stohne wrote: |
2 |
> Mick said the following on 2007-04-05 19:07: |
3 |
> | ... |
4 |
> | Hmm, neither less not cat give me color output. Passing --color=y to |
5 |
> |
6 |
> either |
7 |
> |
8 |
> | tells me things like: |
9 |
> | ============================== |
10 |
> | There is no color=y option ("less --help" for help) |
11 |
> | ============================== |
12 |
> | |
13 |
> | I also tried --color but it's all still shown in black & white. How |
14 |
> |
15 |
> do you |
16 |
> |
17 |
> | pipe a file and get it to show in color? Am I missing something in |
18 |
> | my .bashrc or elsewhere? |
19 |
> |
20 |
> To make less interpret color escape sequences, you need the -R option. |
21 |
> export LESS=-R in your shell startup script and you-ll have it as |
22 |
> default. Generally, you don't want to use less -r, which allows |
23 |
> arbitrary control characters through to affect the terminal (which tend |
24 |
> to create major garbage). |
25 |
> |
26 |
> Color is added via ANSI escape sequences, which don't work in all |
27 |
> displays/terminals/consoles, but as an example: grep is smart enough to |
28 |
> detect this and won't use color (even when specified) if you're sending |
29 |
> the output via a pipeline. Otherwise, if you piped the output, eg to |
30 |
> less, the ANSI escape sequences would send garbage to the screen. |
31 |
> |
32 |
> ~ If, on the other hand, that's really what you want to do (without the |
33 |
> garbage), there's a workaround: |
34 |
> |
35 |
> use the --color=always to force it through and call less with the -R |
36 |
> flag (which prints ALL RAW control characters). That way, the color |
37 |
> codes will escape correctly and you'll page through screens of text with |
38 |
> your matched patterns in full color: |
39 |
> |
40 |
> grep --color=always "regexp" the_file_you_want_to_wade_through | less -R |
41 |
> |
42 |
> That should do the trick :) |
43 |
|
44 |
Thank you Tony, |
45 |
|
46 |
That's good. It shows the regexp in colour and makes it easy to find amidst |
47 |
the text. However, what I had in mind was many different colours, like I can |
48 |
see e.g. in vim? Is such a thing possible with cat or less? |
49 |
|
50 |
BTW, I had alias less="less -r" in my .bashrc, but changed to -R as suggested. |
51 |
|
52 |
Happy Easter to All! |
53 |
-- |
54 |
Regards, |
55 |
Mick |