Skip to content

Instantly share code, notes, and snippets.

@thuan1412
Created April 11, 2020 03:52
Show Gist options
  • Save thuan1412/b2396a15a22da15d0b9cf387062f5c9e to your computer and use it in GitHub Desktop.
Save thuan1412/b2396a15a22da15d0b9cf387062f5c9e to your computer and use it in GitHub Desktop.
# Add git branch if its present to PS1
function parse_git_branch() {
output=$( git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )
if [ "$output" = "" ]; then
echo ""
else
echo \(git:"$output"\)
fi
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\]\W\[\033[1;49;32m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\W $(parse_git_branch)\[\033[00m\]\$ '
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment