Setting a nice CONSOLE PROMPT.

If none of the more specific forums is the right place to ask

Setting a nice CONSOLE PROMPT.

Postby john123son » 2020-03-19 09:17

I have been following the Debian 10 installation & Virtual Machine guide @

http://www.preearth.net/phpBB3/viewtopic.php?f=18&t=1183

I liked the following section so I converted it to BB code and now share it.

-------------------------------------

I spent a lot of time investigating how to set a nice console prompt, so I may as well say a little about it. Here is my prompt for the Debian 5 chroot environment

PS1="\[\e[32;1m\](deb5 chroot) \[\e[34m\]\u@\h \[\e[31m\]\w/\[\e[m\]> "

Copy and paste that into a console, hit enter, and you will get a prompt like this:

(deb5 chroot) john@debian /media/cdrom/>

\u is the username; \h is the hostname; \w is the current working directory. Note that double clicking on the name of the current working directory will copy it so that it can be quickly pasted where needed. I have found this very useful.

See man bash for more on this (search for ^PROMPTING).

\e or \033 is the escape character.
The sequences \e[ .... m set display attributes. For example,
\e[31m begins red text,
\e[31;1m begins bold red text,
\e[31;1;4m begins bold underlined red text,
\e[31;1;4;44m begins bold underlined red text on a blue background,
\e[31;1;4;44;5m begins flashing bold underlined red text on a blue background, and
\e[m = \e[0m changes it back to ordinary text.

See man console_codes for more on this.

The above sequences work well to change the display attributes but do not work well with the up and down arrows used to scroll through previous commands. These need to know which characters in the prompt are to be displayed and which are not. To achieve this the non-printing characters are placed between \[ and \].

To make this change permanent, you need to add your new PS1 definition to your ~/.bashrc file. Files beginning with a dot are not shown by ls. Use ls -a to include dot-files.
john123son
 
Posts: 7
Joined: 2020-03-12 09:20

Return to General Questions

Who is online

Users browsing this forum: No registered users and 10 guests

fashionable