UPDATE: I have changed my prompt again, read my bash prompt revisited
Introduction
This is an short but detailed description of a bash prompt. I’m happy with it and haven’t changed it much for a long time. 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 USER@HOSTNAME CURRENT-DIRECTORY $
Time
If more than one terminal is open at one time it can be useful to see when or in wich order commands have been executed. The time format is 4 digits (24 hour clock). To conserve space the usual colon infix (:) is omitted.
Username
The name of the currently logged in user. A maximum of 3 characters are displayed.
Hostname
The system hostname. A maximum of 4 characters are displayed.
Current directory
The current working directory. The full path is shown until a 15 characters limit has been reached, then only the initial letter of each directory leading up the the last one is displayed.
Hostnames, SSH and SSH key indicators:
Format:
SSH-KEY-INDICATOR TIME USER@HOST SSH-INDICATOR CURRENT-DIRECTORY $
Key indicator
The SSH key indicator K
is shown at the leftmost position of the prompt when the SSH key is detected as loaded by an SSH agent. The key to be identified is chosen by setting an environment variable named SSH_KEY_FINGERPRINT
. This can be done just before the prompt code in ~/.bashrc
1 2 3 |
|
Hostname (again)
As seen in the above picture, different host names are automatically given a color to distinguish systems from each other a little bit more.
SSH indicator
The ssh indicator just displays SSH
in a high color contrast towards the middle of the prompt line so that it is clear that you probably are on a remote system. This is a saftey feature.
Git repository meta data
Whats going on here?
The git git section of the prompt will show you things like branch name, if there are unstaged or uncommitted changes, if there are mergeable changes fetched or if all commits are pushed.
These features are straight from git’s bash integration which probably are located in /etc/bash_completion.d/git
The actual prompt code
To use this prompt, paste the following into ~/.bashrc or source it from a script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|