Scroll to Content Posts Index Back to Home Page

Complexity of David

Data Science, Machine Learning, Artificial Intelligence, Visualization, and Complex Systems.

Change PS1 Bash Prompt for Something Informative

My Bash PS1 Prompt is:

1
PS1='\n\[\e[31;1m\]\A\[\e[0m\]:\[\e[36;1m\]\w\[\e[0;36m\]$(parse_git_branch)\n\[\e[32;1m\]\[email protected]\h\[\e[0m\]\$ '

It outputs something like (but with colors)

1
2
16:00:/Volumes/Jazz/Documents/_Web/sixhat.github.com [master]
[email protected]$

If you want to change yours there are many resources online far more comprehensive than what I could fit here. The only trick in my prompt that you might be interested is the $(parse_git_branch) part. This is

1
2
3
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}

and it just checks if you are currently in a git repo, and extracts the branch. Very useful if you work with git.