Relative bash colors that work with all schemes?

07
2014-07
  • Mikhail

    How can I have a "relative" color in bash, rather than hardcoded one? If I specify to use yellow "\033[93m" then it looks bad for those people that use white background.

    Is there a way to specify not a color, but "style" so to speak? like "Highlight" or "Important" or "darken" or "Deprecated"?

  • Answers
  • Spiff

    Bash has nothing to do with this. The bash(1) man page contains no mention of color.

    If your script is changing the text or background color, it's doing so by sending ANSI color escape codes, which are control-character bytes that bash just ignores and passes right through to your terminal emulator just like it sends any ASCII character it wants the terminal to display. You're relying on your terminal emulator to interpret those codes correctly.

    Unfortunately, the ANSI color codes date back to when terminals and PC graphics cards and monitors could only display 8 or 16 colors (if that), so you can't use ANSI color codes for what you're trying to do.

    So, short of building all the infrastructure yourself (terminal emulators that can do relative colors, a new color escape-code system for communicating relative colors to your emulators, and possibly the related terminfo/termcap and other terminal-related software infrastructure work to make sure scripts can reliably recognize that the user is using a terminal emulator that knows these new color tricks), and forcing your users to use it, you'll probably have to do without.

  • Mikhail

    Found this very detailed page on interpreted styles and colors by common terminals. For the original question, on emphasis there are a few tricks that can be done. Just keep in mind that this may not work on all terminals, as it's been pointed out by Spiff, it's up to the terminal to interpret an escaped sequence. From that page:

    echo -e "Normal \e[1mBold"
    

    echo -e "Normal \e[2mDim"
    

    On my terminal I also tried \e[9 which resulted in a strikethrough text.

    Using styles like these is better than using colors because you'll never get an invisible combination, unless you intentionally use \e[8. If some style is ignored by the terminal you will simply see plain text.


  • Related Question

    osx - futurama bash scheme
  • dsg

    Is there a color scheme for the BASH shell that matches the blackboard colors on futurama? enter image description here

    (If it matters, I'm on OSX.)


  • Related Answers
  • Daniel Beck

    Just set the colors in Terminal's Preferences. The profiles, including color settings, are on the second tab there.

    Use the color picker to get the colors off the screenshot.

    enter image description here

  • Adam

    in mac os x, using terminal, go to Terminal -> Preferences. Select the "Settings" Tab from the top bar of the newly shown screen. Select the settings you would like to change from the menu on the left of the window, or hit "+" to create new settings. Once you have selected the shell settings you would like to edit, click "Text" under the Text tab to change the color of the text. Select the "Window Tab" to change the background text.

  • Adam Prax

    Set your terminal forground to the RGB color 30, 214, 123

    Set your terminal background to the RGB color 17, 145, 78