OK, so you know a meeting is boring when you would rather redo your bash prompt. (And, yes, as a consequence, I have come to appreciate the point of running a headless meeting.) I wanted my bash prompt to tell me a number of things:
- Who am I?
- Where am I?
- Which branch of a Git repository am I on?
I wanted color. I wanted a multiline prompt. I wanted it all!
Actually it was pretty easy. Here it is, explanation to follow:
source ~/.git-completion.sh
export PS1='\[\e[0;32m\]\w\[\e[1;33m\]$(__git_ps1 "(%s)")\[\e[0m\]\n\u $ '
The first line loads .git-completion.sh a script distributed with Git that provides autocompletion for Git. Cool! But it also provides the function at work in:
$(__git_ps1 " (%s)")
This will display the branch currently checked out when you are in a Git repository.
The characters:
\[ \]
wrap nonprinting characters, in this case, the color codes:
\e[0;32m
\e[1;33m
\e[1;33m
Finally:
\w
\n
\u
gives you the name of the current directory, a new line, and your user name, respectively.
Well a picture is worth a thousand words:

Post a Comment