LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Adding colors to your motd? (https://www.linuxquestions.org/questions/linux-software-2/adding-colors-to-your-motd-105038/)

herc 10-17-2003 04:53 AM

Adding colors to your motd?
 
I'd like to format my motd with some colors, how can I do it?
:scratch:

Thanks!

bulliver 10-17-2003 06:16 AM

You need to learn about ANSI colour codes. You can find codes in your /etc/DIR_COLOR file.
Then you need to put them in your motd file. You cannot just type them in though...they are non-printing escape sequences. You would do something like this:
Code:

[user@box]$ echo -en "\033[1;34m" > /etc/motd
[user@box]$ echo "Text of your motd file....." >> /etc/motd
[user@box]$ echo -en "\033[0m" >> /etc/motd

If you ran 'cat /etc/motd' this would produce something like:

Text of your motd file.....


The first line puts the beginning escape sequence into the file, in this case...a nice dark blue. BE CAREFUL...as this will overwrite whatever is currently in the file, make sure you back it up first.

The second line is the actuall content of your motd file. You can break it up over multiple lines if you want, just press enter to get a new line BEFORE the closing quote. When you are happy with the layout then type the ' " >> /etc/motd ' bit. Notice that you use the >> redirection operator this time as to append to the motd file, so that your escape sequence isn't overwritten. You could also open the motd file in your favorite editor at this point, and type in your message that way...just dont edit the escape sequence, which will look like this: ^[[0;34m then save the file and complete step three...

The last line closes the colour escape sequence so everything goes back to normal after reading the file.

Flossie 04-09-2004 02:28 AM

has anyone managed to get the above to work.

When I log in my MOTD is in the correct Color but the the command Line stays in that color as wel. The only way I get it to go back to normal is if I do a more on /etc/motd.

This is a bit weird. Has anyone ever seen this before or has anyone managed to add color to there MOTD


Flossie
Mandrake Linux 9.1
:study:

jon_k 05-04-2004 08:41 AM

I know this post might be a little old to bump up, but I am giving relevant information to this thread -- and I may find myself stumbling upon this page through google (like I did originally) and so may many others stumble upon this page.

So don't delete this thread please. Thanks

So here is good information, here os some useful color codes

Code:

Code            Color
-----------------------------
[0;30m      |  black text
[0;31m      |  red
[0;32m      |  green
[0;33m      |  blue
[0;34m      |  purple
[0;35m      |  cyan
[0;36m      |  silver
[0;40m      |  red back.
[0;41m      |  green back.
[0;42m      |  brown back.
[0;43m      |  blue back.
[0;44m      |  purple back.
[0;45m      |  cyan back.
[0;46m      |  silver back.

Additionally good reading about the subject can be found at http://www.linuxgazette.com/node/view/8367

iluvatar 05-04-2004 08:52 AM

read the Bash-Prompt-HOWTO, very nice stuff. it explains a lot about those color codes, including background colors, blinking text and such... it's about changing the bash-prompt but there's much info on the escape sequences in there. read the HOWTO here. full color table:

Code:

+------------------------------------------------------------+
|Black      0;30    Dark Gray    1;30                    |
|Blue        0;34    Light Blue    1;34                    |
|Green      0;32    Light Green  1;32                    |
|Cyan        0;36    Light Cyan    1;36                    |
|Red        0;31    Light Red    1;31                    |
|Purple      0;35    Light Purple  1;35                    |
|Brown      0;33    Yellow        1;33                    |
|Light Gray  0;37    White        1;37                    |
+------------------------------------------------------------+

have fun with this!

Flossie: the echo -en "\033[0m" >> /etc/motd line will reset color info so your prompt should be normal...

greetz,
.-=~ iluvatar ~=-.

bulliver 05-04-2004 04:56 PM

Flossie: Yeah, I got a colours using the method I explained directly above your post. Don't forget the closing sequence so it goes back to normal!!!


All times are GMT -5. The time now is 09:37 AM.