This is an short but detailed description of my current bash prompt. The main focus is to highlight important information and conserve display space by keeping the prompt line as short as possible without sacrificing too much information.
Basic prompt functions
Format:
TIME USERALIAS/USERNAME@HOSTALIAS/HOSTNAME CURRENT-DIRECTORY $/#
Time
If more than one terminal is open at one time it can be useful to see when or in which order commands have been executed. The time format is 4 digits (24 hour clock). To conserve space the usual colon infix (:) is omitted.
User alias or name
Either alias to the real user name, otherwise a maximum of 4 characters of the actual user name are displayed.
Host alias or name
Either an alias to the real host name, otherwise a maximum of 4 characters of the actual host name are displayed.
Current directory
The current working directory. The full path is shown until a 25 characters limit has been reached, then only the initial letter of each directory leading up the the last one are displayed.
Last part
$ for a normal user or # for root prompt.
If the previous command exited with an error the normal user prompt is replaced with ¤%&! and the root prompt with !!! #.
The SSH indicator ssh is shown after the current working directory when connected though ssh.
If an ssh agent is running the ssh prompt is prefixed with an @.
Hostname (again)
As seen in the picture above, the host name alias has a red background. This is because the system is identified as a server.
Git/version controlled meta data
Whats going on here?
The git vcs section of the prompt will show you branch name and if there are unstaged or uncommitted changes.
Vcprompt is called if it’s installed to support git/mercurial/subversion, otherwise git’s default prompt functions are used.
The actual prompt code
To use this prompt, paste the following into ~/.bashrc :