-
-
Save seivan/c1ae9f2830a9b0b29a9bfb45257c1c9c to your computer and use it in GitHub Desktop.
Display Git commit hash and branch name and enable git completions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Also works
git name-rev HEAD --name-only
for branch not sure what the difference is.