Tired of Overly Complicated Shell Prompts?
- EN
- ES
Tired of overly complicated shell prompts? I am 😡
Since some time ago there seems to be a trend of overly complicated shell prompts. A hell lot of useless information, infinite colors, complex scripts, plugins, multiline prompts… multiline prompts!!
I spend some time in a shell and wonder what I really need in my bash prompt.
By default, a normal installation will show username and host. Do I relly need that? Probably not, I know who I am and I know where I am.
If not (I’m a different user or I am in a different place) chances are that I will have this information.
But most of the time, I am who I am and I stay in my local machine.
There are a few pieces of information that I find useful though:
- what time is it? Yes, there is clock in the top bar of the desktop, but it’s too far away and I am not looking at it. I helps with time management!
- which directory I am in, definitely useful
- In case I’m working in version controlled stuff, which branch am I working in, is my git repo clean? After a lot of hesitation, I decided this might be useful too.
Enough.
So this is all I need:
How to get it?
$ cat ~/.bashrc
[...]
# bash simple prompt with git information
function parse_git_dirty {
[[ $(git status --porcelain 2> /dev/null) ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ (\1$(parse_git_dirty))/"
}
export PS1="\[\e[32m\]\A \[\e[96m\]\w\[\e[93m\]\$(parse_git_branch)\[\e[00m\] $ "
[...]
Enjoy your simple bash prompt!