How to colorize a hint on FreeBSD / cshrc?

I am responsible for managing many servers, I want to configure my tips for each of them so that I don’t get confused about where I entered the system.

I edited the .cshrc files and put them in them:

 set prompt=`whoami`@`hostname -s`:$cwd'$ ' 

But I would like to color this invitation so that it stands out a little more. Maybe green with white text or something else. How can i do this? I am not very familiar with shell syntax.

I am using an SSH connection from the standard terminal that comes with Ubuntu, if relevant.

+8
source share
2 answers

This page has a pretty good explanation, although the syntax is slightly different in csh . Here is what I came up with:

 set prompt="%{\e[32;1m%}%n%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} " # root variation: set prompt="%{\e[31;1m%}root%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%/%{\e[37m%}#%{\e[0m%} " 

update: the previous hint that I had was not actually updated when you changed directories. using %n , %~ and %m instead of $cwd or pwd actually upgrade. look here .

%{ ... %} means that the material between them must take a width of 0
\e[ ... m defines colors and bold. \e avoids [ which seems necessary (I believe this is equivalent to \033 ), m means end.

Use 0 as the color to restore the default settings.

If you want to set the color and background, just separate the numbers with a semicolon. Use 1 to enable bold.

Refer to this table to select colors:


(source: funtoo.org )

So, for example, "Hello World", in bold, blue on a red background will be %{\e[36;41;1m%}Hello World%{\e[0m%}

+12
source

As far as I know, FreeBSD comes with tcsh by default. See examples .

Another list for other shells (bash, csh , tcsh, ksh, etc.). available. Taken from this link and tested with tcsh (I don't have csh):

To color the invitation, you will want to place this symbol in your invitation. %{\033[Xm%} .

Some colors require a semicolon to display. Yellow [...] is 1; 33 don't use only 33, or it will come out brown. If you have 0; 31, you do not need to post 0.

Colors - ANSI. See the ANSI color list ; just replace X with the color code.

X = 0 discards colors: %{\033[0m%} .

+3
source

Source: https://habr.com/ru/post/923432/


All Articles