diff options
author | Victor Toso <victortoso@redhat.com> | 2015-11-16 11:35:32 +0100 |
---|---|---|
committer | Victor Toso <victortoso@redhat.com> | 2015-11-16 11:35:32 +0100 |
commit | f786e3e6f164c76368181999df4602fb3bd5f6a3 (patch) | |
tree | 19f8529724c40c6e9a327320a01435bd4a144733 | |
parent | 1b3c157ecd5fe4574270eb227959e187fd6f0eae (diff) |
bashrc: include branch name on PS1
This is just a simple hack to have the branch name when entering in a
.git folder. It works in a way to avoid start working on something in
the wrong branch :)
vim-airline and vim-fugitive does help as well..
Failure: the branch name is only set when entering in the git folder...
if the branch is changed after that, it will not update.
-rw-r--r-- | bashrc | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -39,20 +39,38 @@ fi # ---------------------------------------------------------------------------- # # ----- New stuff usually goes here :-) -------------------------------------- # # ---------------------------------------------------------------------------- # +function get_git_branch() +{ + if [ -d "$PWD/.git" ] + then + branch=`cat $PWD/.git/HEAD | cut -d'/' -f 3` + eval "$1='$branch'" + fi +} + PATH=$HOME/.local/bin:$PATH PATH=$PATH:$HOME/scripts EDITOR=vim BROWSER=firefox #LS_COLORS='di=1:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:*.deb=90' +PROMPT_COMMAND=' +get_git_branch branch +if [ "$branch" ] +then + branch="($branch) " +fi +default="\[$txtwht\] \W \[$txtylw\]$branch" if [ `whoami` == "root" ]; then - PS1="\[$bldred\](\h)\[$txtwht\] \W\[$bldred\] #\[$txtwht\]" + PS1="\[$bldred\](\h)$default\[$bldred\]# \[$txtwht\]" else if [ $UNDER_JHBUILD ]; then - PS1="\[$bldpur\](jhbuild)\[$txtwht\] \W\[$bldgrn\] $\[$txtwht\]" + PS1="\[$bldpur\](jhbuild)$default\[$bldgrn\]$ \[$txtwht\]" else - PS1="\[$bldgrn\](\h)\[$txtwht\] \W\[$bldgrn\] $\[$txtwht\]" + PS1="\[$bldgrn\](\h)$default\[$bldgrn\]$ \[$txtwht\]" fi fi - +unset branch +unset default +' # vim:ts=4:sw=4 |