From f786e3e6f164c76368181999df4602fb3bd5f6a3 Mon Sep 17 00:00:00 2001 From: Victor Toso Date: Mon, 16 Nov 2015 11:35:32 +0100 Subject: 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. --- bashrc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/bashrc b/bashrc index 2dc5332..edfcb43 100644 --- a/bashrc +++ b/bashrc @@ -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 -- cgit v1.2.3