How to color a prompt on FreeBSD/cshrc?

csh prompt
zsh prompt colors
zsh bold prompt
tcsh cshrc example
set prompt color
change terminal color linux command line
tcsh color codes
customize zsh prompt

I'm being put in charge of managing a bunch of servers, I want to set up my prompts on each of them so that I don't get confused as to where I am logged in to.

I've edited my .cshrc files and put this in them:

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

But I'd like to color that prompt so it stands out a bit more. Maybe green with white text or something. How can I do that? I'm not very familiar with the shell syntax.

I'm SSH-ing in from the standard terminal that comes with Ubuntu, if that's relevant.

This page has a pretty good explanation, although the syntax is a bit different in csh. Here's 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 prompt I had here didn't actually update when you changed directories. using %n, %~ and %m instead of $cwd or pwd actually update. see here.

%{ ... %} means the stuff between should take 0-width \e[ ... m specifies the colors and bolding. \e escapes the [ which seems to be necessary (I believe it's equivalent to \033), the m signifies the end.

Use 0 as your color to reset to default.

If you want to set a color and background, simply separate the numbers with semi-colons. Use 1 to enable bolding.

Consult this table to choose your colors:

(source: funtoo.org)

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

Putting colour in your shell, cshrc. It is also possible to modify the colours as well, but I just use the defaults. As for the path, set a shell prompt that� I prefer to get rid of the user specific settings file /root/.cshrc by deleting all the lines on it except for the comments at the start (hint - Ctrl+K in the ee editor deletes the line you're in) and then edit the system wide /etc/csh.cshrc file instead, so the changes apply to all users which use csh.

To my knowledge FreeBSD comes with tcsh by default. Have a look at the examples.

Another list for other shells as well (bash, csh, tcsh, ksh, etc.) is available. Taken from that link and tested with tcsh (I do not have csh installed):

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

Certain colors need a semicolon in order to appear. Yellow […] is 1;33 do not use just 33 or it will come out brown. If you have a 0;31 you don't need to place the 0.

The colours are ANSI. Have a look at the ANSI colours list; simply replace X with the colour code.

X = 0 resets the colours: %{\033[0m%}.

How to get a colored prompt on FreeBSD — SoCruel.NU, FreeBSD uses the csh as standard shell for the user accounts. This post shows how to get some colors with your prompt. Requirements. The� Hello Am very new to linux/unix, workin in it since 10 days only. I had started with bash and now I need to work in tcsh. I have changed shell for my user profile using 'chsh' I use gedit for script writing.

# Add these lines to your ~/.cshrc.mine file on the linux grace machines...

# Colors!
set     red="%{\033[1;31m%}"
set   green="%{\033[0;32m%}"
set  yellow="%{\033[1;33m%}"
set    blue="%{\033[1;34m%}"
set magenta="%{\033[1;35m%}"
set    cyan="%{\033[1;36m%}"
set   white="%{\033[0;37m%}"
set     end="%{\033[0m%}" # This is needed at the end... :(

# Setting the actual prompt

set prompt="${green}%n${blue}@%m ${white}%~ ${green}%%${end} "

# Clean up
unset red green yellow blue magenta cyan yellow white end

Coloring the tcsh prompt, Add these lines to your ~/.cshrc.mine file on the linux grace machines # don't worry too much about what they mean. # Colors! set red="%{\033[1;31m%}" set� The C-shell (both csh and tcsh) equivalent of .bashrc is .cshrc. Create it, if it doesn't exist, and add that line to it. Create it, if it doesn't exist, and add that line to it. share | improve this answer | follow |

Customizing your shell prompt, tcsh. I'll start with tcsh, since it's the default BSD and Mac OS X shell. Here's a very The 31 is the color code, and the %m is obviously where you put whatever � This you can do by simply copying .cshrc to .tcshrc. Now that you have installed tcsh, you can adjust your prompt. You can find the details in the manual page for tcsh, but here is a line to put in your .tcshrc that will tell you how many commands you have typed, what time it is, and what directory you are in.

Tcsh / csh fancy shell prompt with date, color and more � GitHub, Tcsh / csh fancy shell prompt with date, color and more .cshrc. # $FreeBSD: releng/10.3/etc/root/dot.cshrc 243893 2012-12-05 13:56:39Z eadler� Hydro- told me where to look. If you want the prompt set each time you login, put the code in either .tcshrc or .login in your home directory. But my opinion is that you should use the shell-specific file for shell-specific things. In other words, I recommend .tcsh over .login.

Changing text color in c-shell, Setting the prompt is done with: set prompt="some string". in your case you need to notify csh that certain elements have zero width by� To color the prompt you will want to place this symbol in your prompt.%{\033[Xm%}. Also right after your "set prompt = " you will want to place a if you don't the color prompts will not work.Example:set prompt = " %{\033[31m%}%m %n %{\033[0m%}>". set prompt = "red text hostname whoami normal display>".

Comments
  • Well, the .cshrc file existed, and editing that changed my prompt. Does tcsh use the same file? How can I find out which one is running?
  • @Mark: Yes, it uses the same file. My one has a if ($?tcsh) then block for tcsh-specifics. Check using env | grep -i shell.
  • I didn't say that. They're just not very well explained. Which part is the start of the color? The stop? What do the different parts mean? Is there a table or colors for reference?