Skip to content

Instantly share code, notes, and snippets.

@notogawa
Created February 22, 2017 04:33
Show Gist options
  • Save notogawa/a3697d119bec32033a6f18a30e2beb13 to your computer and use it in GitHub Desktop.
Save notogawa/a3697d119bec32033a6f18a30e2beb13 to your computer and use it in GitHub Desktop.
function init-prompt-git-branch()
{
git symbolic-ref HEAD 2>/dev/null >/dev/null &&
echo "($(git symbolic-ref HEAD 2>/dev/null | sed 's/^refs\/heads\///'))"
}
if which git 2>/dev/null >/dev/null
then
export PS1_GIT_BRANCH='\[\e[$[COLUMNS]D\]\[\e[1;31m\]\[\e[$[COLUMNS-$(length $(init-prompt-git-branch))]C\]$(init-prompt-git-branch)\[\e[$[COLUMNS]D\]\[\e[0m\]'
else
export PS1_GIT_BRANCH=
fi
export PS1="\[\e[32;1m\]\u@\H \[\e[33;1m\]\w $PS1_GIT_BRANCH\n\[\e[36;1m\]\t \[\e[0m\]\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment