Skip to content

Instantly share code, notes, and snippets.

@jidckii
Last active June 28, 2019 12:02
Show Gist options
  • Save jidckii/d1683939e150d36131d12efe414e7a15 to your computer and use it in GitHub Desktop.
Save jidckii/d1683939e150d36131d12efe414e7a15 to your computer and use it in GitHub Desktop.
Display current git branch in bash prompt
# Display current git branch in bash prompt
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_blue=`tput setaf 4`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
if git diff --quiet 2>/dev/null >&2
then
gitver="${c_green} [${gitver}]${c_sgr0}"
else
gitver="${c_red} ![${gitver}]${c_sgr0}"
fi
else
return 0
fi
echo -en "${gitver}"
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\t:\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\e[00m\]:$(parse_git_branch)\[\033[00m\]\n\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\t \w\[\e[00m\]\$ '
fi
unset color_prompt force_color_prompt
@jidckii
Copy link
Author

jidckii commented Jun 28, 2019

screen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment