title: Colored shell script output library
body: <p>I am looking for a definitive way to build shell scripts that generates colored output. </p>
  
  <p>Unfortunately I am having a hard time finding an appropriate lib or good technique for doing this. I found a lot of helpful but simple examples like <a href="http://www.legroom.net/2010/06/18/display-colored-output-shell-scripts" rel="noreferrer">this</a>. Also the most comprehensive guide that I found until now is <a href="http://www.bashguru.com/2010/01/shell-colors-colorizing-shell-scripts.html" rel="noreferrer">this one</a>. </p>
  
  <p>Before I start writing my own library, I want to check if anyone already wrote it</p>
  
  <p>If your solution does not fit into the observations below thats not a problem. I would like also to read it so it can help me out if decide to write my own solution</p>
  
  <p>My main concerns/observations:</p>
  
  <ul>
  <li><strong>Needs to be safe</strong>. Want to avoid garbage output as not all terminals or pagers/editors (like less, more, vim, and so on) support colored output or more styled output (bold, blinked, italic, etc)</li>
  <li><strong>Needs to be easy and readable</strong>. Using <a href="http://en.wikipedia.org/wiki/ANSI_escape_code#graphics" rel="noreferrer">ANSI escape codes</a> directly is horrible: <code>echo -e '\033[32mthis is ugly and \033[1;32mvery green\033[0m'</code></li>
  <li><strong>Needs to give me access to the whole color palette and styles</strong> for foreground and background text. Most of the examples I found uses only the basic colors for foreground text only.</li>
  <li><strong>Its preferable to use only simple commands</strong> like bash or simpler shells built in commands and/or common commands that can be found on most operating systems. For instance I can use <a href="https://stackoverflow.com/questions/1489183/colorized-ruby-output">colorize</a> but I would need ruby (that's somewhat ok) and the colorize gem installed (not ok)</li>
  <li><strong><a href="http://linux.101hacks.com/ps1-examples/prompt-color-using-tput/" rel="noreferrer">Tput</a> seems to be a good option</strong> as it can manipulate the shell cursor quite well, but it is somewhat simpler/less flexible</li>
  </ul>
  
  <h2>Edit</h2>
  
  <p>After some research on terminal control and output formatting, I am writing <a href="https://gist.github.com/bcap/5682077#file-terminal-control-sh" rel="noreferrer">this gist</a> that tries to accomplish this. So far it is doing quite well</p>