Skip to content

Instantly share code, notes, and snippets.

@zaps166
Last active May 27, 2020 11:38
Show Gist options
  • Save zaps166/099af67a6f0047e557c4ca431f55cd22 to your computer and use it in GitHub Desktop.
Save zaps166/099af67a6f0047e557c4ca431f55cd22 to your computer and use it in GitHub Desktop.
Display Git commit hash and branch name and enable git completions
getGitInfo()
{
checksum=$(git rev-parse --short HEAD 2> /dev/null)
branch=$(git symbolic-ref --short HEAD 2> /dev/null)
if [ ! -z $branch ] && [ ! -z $checksum ]; then
echo -e " ($branch $checksum)"
elif [ ! -z $checksum ]; then
echo -e " ($checksum)"
elif [ ! -z $branch ]; then
echo -e " ($branch)"
fi
}
if [ $EUID == 0 ] ; then
PS1='\[\033[01;31m\][$? \u@\h\[\033[01;36m\] \w\[\033[01;31m\]]\[\033[01;35m\]$(getGitInfo)\[\033[01;31m\]\$\[\033[00m\] '
else
PS1='\[\033[01;32m\][$? \u@\h\[\033[01;37m\] \w\[\033[01;32m\]]\[\033[01;35m\]$(getGitInfo)\[\033[01;32m\]\$\[\033[00m\] '
fi
OS=$(uname)
if [ $OS == "Darwin" ]; then
GIT_COMPLETION_PATH="/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash"
if [[ ! -e $GIT_COMPLETION_PATH ]]; then
GIT_COMPLETION_PATH="/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash"
fi
else
GIT_COMPLETION_PATH="/usr/share/git/completion/git-completion.bash"
fi
[ -r $GIT_COMPLETION_PATH ] && . $GIT_COMPLETION_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment