Skip to content

Instantly share code, notes, and snippets.

@lissahyacinth
Created July 31, 2018 12:29
Show Gist options
  • Save lissahyacinth/acccd266662674c4d02e86f85e789b10 to your computer and use it in GitHub Desktop.
Save lissahyacinth/acccd266662674c4d02e86f85e789b10 to your computer and use it in GitHub Desktop.
# Changing Prompt for Bash
inside_git_repo="\$(git rev-parse --is-inside-work-tree 2>/dev/null)"
parse_git_branch() {
if [ "$inside_git_repo" ]; then
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
else echo ""
fi
}
parse_git_commit() {
if [ "$inside_git_repo" ]; then
git log --pretty=format:'%h' -n 1 2> /dev/null | tr -d '\n'
else echo ""
fi
}
export PS1="\W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] \$(parse_git_commit) \$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment