Color output from shell command in Ruby

Here is a simple Ruby script:

puts `ls -laG`

In OS X ls, -G for color.

When running under bash, I get color output. When the above is executed from a Ruby script, I do not see the ANSI color or escape sequence in the resulting result.

From what I read, I think this is because the script does not work like tty. Is there a way to run a command as if it were running under a true tty session - or something like that?

+3
source share
2 answers

ls man page OS X, . CLICOLOR (, -G) CLICOLOR_FORCE ( ).

, , , ...

puts `env CLICOLOR=1 CLICOLOR_FORCE=1 ls -la`

.profile. env, , . -G, CLICOLOR .

+7

man- CLICOLOR_FORCE.

+3

Source: https://habr.com/ru/post/1709734/


All Articles