Index


Key Points
Escape sequences and Color Codes
PS1 Examples
Fancey Letters
Resources
SHELL PROMPT

SHELL PROMPT CUSTOMISATION USING PS1

The special shell variable is used to control the bash prompt. These shell variables are PS1, PS2, PS3, and PS4. Each variable is used for specific purposes. The value of these variables is executed as a command before displaying the primary prompt. The PS1 variable contains the value of the default prompt.


Just take out the terminal and try typing
bash
PS1="hello >> "

Now you might understand how it works.
So If you put this command in your bashrc file, you get this shell prompt forever.
You can have fancy charectors and different colors in your prompt. You can also fetch some information like username, time, current working directory etc as well.

Key Points


Escape sequences and Color Codes

Commonly Used Escape Sequence

backlash-escaped Characterpurpose
\uIt is used to display the current username.
\hIt is used to the name of the computer name.
\HIt is used to the name of the hostname.
\dIt is used to display the date with weekday name, month name, and date.
\wIt is used to display the full path of the current working directory.
\WIt is used to display the last fragment of the current working directory.
\tIt is used to display the current time in 24-hour format.
\TIt is used to display the current time in 12-hour format.
\@It is used to display the current time in 12-hour format with AM/PM.
\nJIt is used to add the new line.
\eIt is used to add an ASCII escape character.
\vIt is used to display the version of the bash.
JillSmith
\VIt is used to display the version of the bash with patch level.


Graphics Redention Parameter

nNameNote
0Reset or normalAll attributes off
1Bold or increased intensityAs with faint, the color change is a PC (SCO / CGA) invention.[38][better source needed]
2Faint, decreased intensity, or dimMay be implemented as a light font weight like bold.[39]
3ItalicNot widely supported. Sometimes treated as inverse or blink.[38]
4UnderlineStyle extensions exist for Kitty, VTE, mintty and iTerm2.[40][41]
5Slow blinkSets blinking to less than 150 times per minute
6Rapid blinkMS-DOS ANSI.SYS, 150+ per minute; not widely supported
7Reverse video or invertSwap foreground and background colors; inconsistent emulation[42]
8Conceal or hideNot widely supported.
9Crossed-out, or strikeCharacters legible but marked as if for deletion. Not supported in Terminal.app
10Primary (default) font -
11–19Alternative fontSelect alternative font n − 10
20Fraktur (Gothic)Rarely supported
21Doubly underlined; or: not boldDouble-underline per ECMA-48,[5]: 8.3.117  but instead disables bold intensity on several terminals, including in the Linux kernel's console before version 4.17.
22Normal intensityNeither bold nor faint; color changes where intensity is implemented as such.
23Neither italic, nor blackletter -
24Not underlinedNeither singly nor doubly underlined
25Not blinkingTurn blinking off
26Proportional spacingITU T.61 and T.416, not known to be used on terminals
27Not reversed -
28RevealNot concealed
29Not crossed outGiven in above table
30–37Set foreground colorGiven in above table
38Set foreground colorNext arguments are 5;n or 2;r;g;b
39Default foreground colorImplementation defined (according to standard)
40–47Set background colorGiven in above table
48Set background colorNext arguments are 5;n or 2;r;g;b
49Default background colorImplementation defined (according to standard)
50Disable proportional spacingT.61 and T.416
51FramedImplemented as "emoji variation selector" in mintty
52EncircledImplemented as "emoji variation selector" in mintty
53OverlinedNot supported in Terminal.app
54Neither framed nor encircled -
55Not overlined -
58Set underline colorNot in standard; implemented in Kitty, VTE, mintty, and iTerm2. Next arguments are 5;n or 2;r;g;b.
59Default underline colorNot in standard; implemented in Kitty, VTE, mintty, and iTerm2. `
60Ideogram underline or right side lineRarely supported
61Ideogram double underline, or double line on the right sideRarely supported
62Ideogram overline or left side lineRarely supported
63Ideogram double overline, or double line on the left sideRarely supported
64Ideogram stress markingRarely supported
65No ideogram attributesReset the effects of all of 60-64
73SuperscriptImplemented only in mintty
74SubscriptImplemented only in mintty
75Neither superscript nor subscriptImplemented only in mintty
90–97Set bright foreground colorNot in standard; originally implemented by aixterm
100–107Set bright background colorNot in standard; originally implemented by aixterm


Background and Text Color

Background ColorsForeground Colors
Black = 40Black = 30
Red = 41Red = 31
Green = 42Green = 32
Yellow = 43Yellow = 33
Blue = 44Blue = 34
Purple = 45Purple = 35
Cyan = 46Cyan = 36
White = 47White = 37
RGB colors = 48RGB Colors = 38

>

Format

Example

bash
\[\e[38;2;0;30;30m\]

bash
\[\e[48;2;0;30;30m\]


PS1 Examples

bash
PS1="╭─────────🮙🮙 NAME\n│\u 🯊 \w\n╰─>> "


bash
PS1="\[\e[32;1m╭─────────🮙🮙 NAME\n\e[32m│\e[36m\u \e[37m🯊\e[33m\w\n\e[32m╰─>> \e[0m\]"


bash
PS1="\[\e[32;1m\]╭─────────\[\e[37m\]🮙🮙\[\e[32m\]\[\e[47m\] NAME \[\e[0m\]🭬\n\[\e[32m\]│\[\e[47m\]\[\e[36m\]\u \[\e[0m\]🭬\[\e[0m\]\[\e[37m\] \[\e[33m\]\w\n\[\e[32m\]╰─>>\[\[\e[0m\]"


bash
PS1="\[\e[32;1m\]╭─────\[\e[38;2;200;200;160m\]🮙🮙\[\e[38;2;50;50;50;48;2;200;200;160m\]NAME \[\e[0;38;2;200;200;160m\]🭬\n\[\e[32m\]│\[\e[38;2;0;30;30m\]🭨\[\e[32;48;2;0;30;30;1m\] \u\[\e[0;42;38;2;0;30;30m\]🭬\[\e[0;42;38;2;0;40;40;1m\]\w \[\e[0;32m\]🭬\[\e[0;32m\]\n╰─>> \[\e[0m\]"


bash
 PS1="\[\e[32;1m\]╭─────\[\e[38;2;200;200;160m\]\[\e[38;2;50;50;50;48;2;200;200;160m\] \t \[\e[0;38;2;200;200;160m\]\n\[\e[32m\]│\[\e[38;2;0;30;30m\]\[\e[32;48;2;0;30;30;1m\] \u\[\e[0;42;38;2;0;30;30m\]\[\e[0;42;38;2;0;40;40;1m\] \w \[\e[0;32m\]\[\e[0;32m\]\n╰─>> \[\e[0m\]"


Fancy Letters

░ ▒ ▓ │ ┤ ╡ ╢ ╖ ╕ ╣ ║ ╗ ╝ ╜ ╛ ┐ └ ┴ ┬ ├ ─ ┼ ╞ ╟ ╚ ╔ ╩ ╦ ╠ ═ ╬ ╧ ╨ ╤ ╥ ╙ ╘ ╒ ╓ ╫ ╪ ┘ ┌ █ ▄ ▌ ▐ ▀ ⌠ ⌡ ░ ▒ ▓ │ ┤ ╣ ║ ╗ ╝ ┐ C └ ┴ ┬ ├ ─ ┼ ╚ ╔ ╩ ╦ ╠ ═ ╬ D ┘ ┌ █ ▄ ▀ ╝ ╗ ╔ ╚ ╣ ╩ ╦ ╠ ═ ║ ╬ ▀ ▄ ┘ ┐ ┌ └ ┤ ┴ ┬ ├ ─ │ ┼ █ ┘ ┐ ┌ └ ┼ ─ ├ ┤ ┴ ┬ │ ╷ ╶ ┌ ╴ ┐ ─ ┬ ╵ │ └ ├ ┘ ┤ ┴ ┼ ╭ ╮ ╰ ╯ ▘ ▝ ▀ ▖ ▍ ▞ ▛ ▗ ▚ ▐ ▜ ▃ ▙ ▟ ▉ ╵ ╶ └ ╷ │ ┌ ├ ╴ ┘ ─ ┴ ┐ ┤ ┬ ┼ ╧ - ╟ ╚ ╤ ║ ╔ ╠ ╢ ╝ ═ ╩ ╗ ╣ ╦ ╬ ╵ ╶ └ ╷ │ ┌ ├ ╴ ┘ ─ ┴ ┐ ┤ ┬ ┼ ▀ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▉ ▊ ▋ ▌ ▍ ▎ ▏ ▐ ░ ▒ ▓ ▔ ▕ ▖ ▗ ▘ ▙ ▚ ▛ ▜ ▝ ▞ ▟ ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏ ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟ ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯ ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿ ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯ ╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿

Resources

--- End of Blog ---