Skip to content

Instantly share code, notes, and snippets.

@alecthegeek
Created August 21, 2012 05:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alecthegeek/3411900 to your computer and use it in GitHub Desktop.
Save alecthegeek/3411900 to your computer and use it in GitHub Desktop.
Fix for Git Prompt in Homebrew
# Upgraded git using Homebrew and now your __git_ps1() fails. Try something like this
# NB Still very fragile as had embedded version no
# enable git programmable completion features
if [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
. /usr/local/etc/bash_completion.d/git-completion.bash
fi
# enable git prompt
if [ -f /usr/local/Cellar/git/1.7.12/share/git-core/contrib/completion/git-prompt.sh ]; then
. /usr/local/Cellar/git/1.7.12/share/git-core/contrib/completion/git-prompt.sh
PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w \$(__git_ps1 \" (%s)\")$"
fi
@tapichu
Copy link

tapichu commented Aug 21, 2012

You could replace /usr/local with brew --prefix and /usr/local/Cellar/git/1.7.12 with brew --prefix git to make it more robust:

if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then
    . `brew --prefix`/etc/bash_completion.d/git-completion.bash
fi

if [ -f `brew --prefix git`/share/git-core/contrib/completion/git-prompt.sh ]; then
    . `brew --prefix git`/share/git-core/contrib/completion/git-prompt.sh
    PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w \$(__git_ps1 \" (%s)\")$"
fi

@hugodes
Copy link

hugodes commented Jul 2, 2019

Just in case someone stumbles upon this in 2019+

Working code would now be:

if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then
    . `brew --prefix`/etc/bash_completion.d/git-completion.bash
fi

if [ -f `brew --prefix`/etc/bash_completion.d/git-prompt.sh ]; then
    . `brew --prefix`/etc/bash_completion.d/git-prompt.sh
    PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w \$(__git_ps1 \" (%s)\")$"
fi

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