Skip to content

Instantly share code, notes, and snippets.

@cbrunnkvist
Forked from burpnoes/.bash_profile
Last active February 13, 2024 01:40
Show Gist options
  • Save cbrunnkvist/b5c9beb10bcfacc17497094eabf0bcfa to your computer and use it in GitHub Desktop.
Save cbrunnkvist/b5c9beb10bcfacc17497094eabf0bcfa to your computer and use it in GitHub Desktop.
Bash git prompt and command completion with Xcode / Mac OS X >= Mavericks (no Homebrew required)
if [ -f /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash ]; then
. /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
fi
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
# configuration variables as documented in:
# https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh#L8
#
GIT_PS1_SHOWDIRTYSTATE="yes"
# GIT_PS1_SHOWSTASHSTATE
GIT_PS1_SHOWUNTRACKEDFILES="yes"
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWCOLORHINTS="yes"
# GIT_PS1_STATESEPARATOR
# GIT_PS1_DESCRIBE_STYL
# GIT_PS1_HIDE_IF_PWD_IGNORED
export PROMPT_COMMAND='__git_ps1 "\u@\h:\W" "\\\$ ";'
@billfeth
Copy link

billfeth commented Jan 5, 2024

Thank you for sharing this. Consider using xcode-select rather than an explicit path to /Applications/Xcode.app. That will allow you to use the installed Xcode, regardless of whether it was renamed or if the app is installed in another folder.

# Include git command completion macros
xcodeGitCompletion=$(xcode-select -p)/usr/share/git-core/git-completion.bash
if [ -f $xcodeGitCompletion ]; then
  source $xcodeGitCompletion
fi

@cbrunnkvist
Copy link
Author

cbrunnkvist commented Feb 10, 2024

Thanks for the feedback! Yup, that is of course the correct thing to do in the name of portability.

And this is quite an old gist, I should probably update it to the equivalent for zsh since that's been the default for years now already. aaakshuly, I think this will work just fine with zsh too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment