7 ms·
No_color: Disabling ANSI color output in various Unix commands
- bArray 7y agoGood idea, especially for parsing program output. It's also not uncommon to find yourself accessing a server through some terminal that doesn't support ANSI colours properly and it ends up breaking.
- derwiki 7y agoIn the meantime, I have a janky (s)trip (c)olor function in my .bashrc to help with this: function sc { sed "s,$(printf '\033')\\[[0-9;]*[a-zA-Z],,g" }
- boardwaalk 7y agoThis seems way more sane and Unix-y than wanting every program to add an option.
- dimator 7y agoI disagree. It seems way more unix-y for programs not to break piping by spewing color codes.
- nils-m-holm 7y agoThe amount of color in modern command line tools is annoying! Sometimes TERM=vt100 helps.
- karmakaze 7y agoTERM=vt100 should always work or the program is broken.
- makecheck 7y agoI wish programs would not colorize. I find that I much prefer post-processing program output to colorize how I please, especially since I may want much better coloring/styling (e.g. mix of foreground/background, bold, underline, and more than basic red/green color choices). Of course, this requires that output has enough semantic clues in the text to colorize meaningfully; that’s a good thing anyway, since it makes the command more flexible for any other purpose like chaining Unix commands.
- stuaxo 7y agoAnd there I am wanting the opposite ;) This is good, it should be submitted as an RFC + track implementation on upstream projects.
- LinuxBender 7y agoI have two functions I use to switch between color and no color. One function also fixes the terminal if I read binary by mistake. I guess I could call them color and nocolor. Edit as required. There's probably a better way to do this. Old habits and such. function sane() { LANG="C";LC_ALL="C";LC_CTYPE="C";export LANG LC_ALL LC_CTYPE; S_TIME_FORMAT=ISO;export S_TIME_FORMAT; TERM=vt102;export TERM; unset IFS; stty sane; tput rs1; echo -e "\033c"; reset; clear; set -o posix; } function utf() { LANG="en_US.UTF-8";LC_ALL="en_US.UTF-8"; LC_CTYPE="en_US.UTF-8";export LANG LC_ALL LC_CTYPE TERM=xterm;export TERM }