lekaha's blog Change the world     Wiki     Blog     Feed

Preference your bash prompt

What is PS1

PS1 denotes Prompt String 1. It is the one of the prompt available in Linux/UNIX shell. When you open your terminal, it will display the content defined in PS1 variable in your bash prompt

Preference it

It is a web site for customizing your bash prompt: http://bashrcgenerator.com/

I would like to display as

[user]@[hostname] [directory] [git user.name] - [git current branch]

Modify your bash profile

Add below script

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
get_git_user_name() {
    git config user.name
}
export PS1="\u@\h \[\033[32m\]\w\[\033[38;5;215m\] \$(get_git_user_name)\[\033[00m\] -\[\033[33m\]\$(parse_git_branch)\[\033[00m\] "

comments powered by Disqus