I am looking to create a simple unix watch
like command using Ruby to run commands. But colours aren't preserved for some commands. For instance, I was able to preserve the colour while executing:
puts %x{ CLICOLOR_FORCE=1 ls -la}
* flag suggestion by john-c
I am assuming its because the commands switch to a printable text only version when the command is invoked via script, possibly to ease further processing. Have heard of this, but don't have the proper pointer/terms to do a research; is there a way to force the coloured output through a Ruby script? Or 'trick' the commands into thinking its invoked via terminal rather than a script?
I tested without success with the following:
puts %x{ CLICOLOR_FORCE=1 rspec --color test_file.rb }
I know there is a well established way to go about this using guard-rspec. But I am pursuing this for a gem that I am building and I need the capability to run arbitrary commands with coloured output preserved.
Any help will be greatly appreciated.