Skip to content

Instantly share code, notes, and snippets.

@keyganker
Last active September 18, 2023 16:27
Show Gist options
  • Save keyganker/6b36ab4bb72a7d7f31dec70055ad851a to your computer and use it in GitHub Desktop.
Save keyganker/6b36ab4bb72a7d7f31dec70055ad851a to your computer and use it in GitHub Desktop.
git branch name prompt in shell #shell
function git_branch {
branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"
if [ "${branch}" != "" ];then
if [ "${branch}" = "(no branch)" ];then
branch="(`git rev-parse --short HEAD`...)"
fi
echo " ($branch)"
fi
}
export PS1='\u@ \[\033[32;40m\]\w\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment