bgibson
bgibson

Reputation: 19115

Is it possible to colorize output piped to more?

I have ls and grep aliased to ls --color=auto and grep --color=auto for colorized output, but when I pipe to more the color is lost.

Neither more nor less seems to have a param for colorizing their output. Is there any way to do this?

Upvotes: 14

Views: 1868

Answers (3)

vhs
vhs

Reputation: 10071

On macOS 10.15 Catalina (darwin 19.0.0) you can colorize the output of ls piped to head, grep, less and more with the following adjustments to your zsh config:

~/.zshrc

alias less="less -R"
alias more="more -R"

~/.zshenv

export GREP_COLOR=always
export CLICOLOR_FORCE=true

Run open x-man-page://command to open the man page for the command command.

Upvotes: 2

je4d
je4d

Reputation: 7838

The problem isn't that more and less aren't colourizing their output, it's that ls is not outputting the colour because it's connected to another process rather than the terminal.

You can't easily get ls to be any smarter about when it outputs colour, but you can add --color to force it to output colour when you're piping it to more

When you have colour output, use ... |less -R to make less pass the colours through to the terminal instead of showing the escape codes as text

Upvotes: 19

jimw
jimw

Reputation: 2598

ls --color | less -r

Tested on Linux, GNU userland.

Upvotes: 4

Related Questions