Tag: color

gnome-terminal color schemes.

Colours
Colours (Photo credit: CherrySoda!)

I was looking for a way to set the terminal colors for gnome. There is a GUI way to change the same by going to the Preferences->Colors. And then you can change the colors that you see in the color pallete in the bottom of the dialog box.

But I was looking at doing it faster and better, and finally I found this page.

http://www.sharms.org/blog/2012/08/gnome-terminal-color-schemes/

Quite interesting and good.

Enhanced by Zemanta

colors in bash scripts

Colours
Colours (Photo credit: CherrySoda!)

I have been trying to understand the color codes for bash for a pretty long time, but somehow never got time to understand this clearly. So this time around when I was writing a script to analyze some logs. I thought I will give it a go and finally understood some part of this.

So, first we will start with this script. This is taken from here.

#!/bin/bash -
#===============================================================================
#
#          FILE:  colortest.sh
#
#         USAGE:  ./colortest.sh
#
#   DESCRIPTION:   http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), [email protected]
#       COMPANY:
#       CREATED: 09/04/12 14:29:47 IST
# Last modified: Sun Apr 15, 2012  06:29PM
#      REVISION:  ---
#===============================================================================

#!/bin/bash
#
#   This file echoes a bunch of color codes to the
#   terminal to demonstrate what's available.  Each
#   line is the color code of one forground color,
#   out of 17 (default + 16 escapes), followed by a
#   test use of that color on all nine background
#   colors (default + 8 escapes).
#

T='gYw'   # The test text

echo -e "\n                 40m     41m     42m     43m\
     44m     45m     46m     47m";

for FGs in '    m' '   1m' '  30m' '1;30m' '  31m' '1;31m' '  32m' \
           '1;32m' '  33m' '1;33m' '  34m' '1;34m' '  35m' '1;35m' \
           '  36m' '1;36m' '  37m' '1;37m';
  do FG=${FGs// /}
  echo -en " $FGs \033[$FG  $T  "
  for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
    #do echo -en "$EINS \033[$FG\033[$BG  \$T  \033[0m";
    do echo -en " \033[$FG\033[$BG  $T  \033[0m";
  done
  echo;
done
echo

This script will give you all the colors that are possible in the bash scripting. And now let’s understand color’s a little more.

There are basically two ways you can use colors and I will illustrate both with echo command.

Before we get into all these, we will see hot to reset the colors:

echo -e "\033[00m"

The first one is the one used in the above script, where in you can use the codes multiple times to get the desired effect. For example, see the screenshot below:

colors in bash
colors in bash

And the other way to achieve the same is to use all the color codes with one escape sequence :

colors in bash
colors in bash

Important to note here is that the “m” is missing.

All the codes that you want can be used separated by “;” and end with “m”. I think I have explained the things.

Enhanced by Zemanta

Try all colors in xterm with script before setting the color

If you are looking for testing the colors on how they would look like in the xterm before you set the color then here is a small script for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash -
#===============================================================================
#
#          FILE:  xterm_colors-test.sh
#
#         USAGE:  ./xterm_colors-test.sh
#
#   DESCRIPTION:  Test all the colors for xterm bg
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:   Amit Agarwal ([email protected]), aka
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  02/18/2011 01:02:51 PM IST
#      REVISION:  1.0
#===============================================================================

cat /usr/share/X11/rgb.txt |sed 's/\([0-9]\{1,3\}[ \t]*\)\{3\}//'|sed 's/^ *//' >~/rgb.txt
while read line
do
bg=$(echo $line)
echo $line
echo "Trying $bg color"
xterm -bg "$bg"&
sleep 5
kill -9 $!
done < ~/rgb.txt

This can be used in various ways but I will leave the choice to you. One option that I should probably still tell is :

Execute a command like ls to see how the settings for dircolors would look like in the terminal. To do this change the line where we are invoking xterm to the below line:

1
xterm -bg "$bg" -e "ls && sleep 5"

Do remember the sleep to some suitable time according to your needs.

Hope this helps you choose the color you want for your xterm background.

Enhanced by Zemanta