moar icon indicating copy to clipboard operation
moar copied to clipboard

No color in Powershell when using pipes

Open cmust opened this issue 1 year ago • 1 comments

Running this command

dir | moar

produces an output with no color.

The equivalent command (ls | moar) in other shells preserves the coloring as expected.

cmust avatar Sep 19 '24 08:09 cmust

I think the reason you're getting color from ls in this case is that you have some configuration enforcing color.

If you want color from dir you need to somehow get dir to color output not only to terminals but to pipes as well.

In GNU ls, you do this by passing --color=always. On BSD ls, setting CLICOLOR_FORCE to some value will force color.

What I expect, and what's probably happening with Powershell is this:

  • dir sees that its output is a pipe rather than a terminal
  • dir adapts by not showing any color
  • moar receives the not-colored stream and shows that

Do you get color from env -i /bin/ls | moar? If not, this demonstrates that you're somehow forcing ls to show color even when piping its output to somewhere else.

walles avatar Sep 19 '24 20:09 walles

No response, closing.

@cmust do re-open as needed!

walles avatar Oct 26 '24 20:10 walles