Create a multi-line Terminal prompt

May 17, '02 08:52:43AM

Contributed by: Viridian

Here's a prompt formatting tip for tcsh: Several tips on this site have helped this glistening wet Unix newbie customize my prompt with command history, time, and directory info, as well as colors. However, as the filepath expands when I'm navigating the tree, any long commands I type at the prompt sometimes get wrapped to another line. I wondered if it were possible to have the "%" symbol appear at the beginning of a new line at all times, so out of idle curiosity one day I put a carriage return ("\n") in my prompt, and to my vast surprise, it worked perfectly. I inserted a carriage return at the beginning of the prompt string as well, so it stands alone on a line by itself, as a sort of informational header, while the percent symbol and cursor appear at the beginning of the next line.

Read the rest of the article for the prompt string, as well as a brief tutorial on ANSI codes and their use in the prompt command...

My Terminal window is set to black with 40% transparency, and I find that Courier Bold Oblique 14 pt. set to cyan is the most legible font for me. My prompt is yellow and white:

set prompt = "\n%{\033[1;93m%}>>>%{\033[0;93m%}[%{\033[0;37m%}\\!\!%{\033[0;93m%}]
[%{\033[0;37m%}%D%w%y%{\033[1;93m%}%P %{\033[0;37m%}EST%{\033[0;93m%}][%{\033[0;37m%}%n
%{\033[0;93m%}@%{\033[0;37m%}%m%{\033[0;93m%}][%{\033[0;93m%}%c03]\n\n%#%{\033[0m%} "
[Author's Note: this is all a single line. There are spaces surrounding the "=" sign, and a single space before the closing double quotation mark. Put in ~/.tcshrc or ~/Library/init/tcsh/environment.mine.]

Here's a quick tutorial on color and ANSI codes. Literal strings are enclosed with %{ and %}. ANSI graphics mode begins with \033[ and ends with m. ANSI color codes are placed between \033[ and m, separated by semi-colons. Thus
%{\033[n;n;nm%}
where n is one of the codes from the list below:

ANSI Color codes
0 = default colour
1 = bold
4 = underlined
5 = flashing text
7 = reverse field
31 = red
32 = green
33 = orange
34 = blue
35 = purple
36 = cyan
37 = grey
40 = black background
41 = red background
42 = green background
43 = orange background
44 = blue background
45 = purple background
46 = cyan background
47 = grey background
90 = dark grey
91 = light red
92 = light green
93 = yellow
94 = light blue
95 = light purple
96 = turquoise
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background

So the string
%{\033[0;1;5;44;93m%}%n
would reset your user name (%n) to default (0), then set it to bold (1), flashing (5), yellow (93) on a blue background (44).

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20020517085243183