I just followed the instructions @ this question in order to get git autocompletion in the terminal. Here are the steps I've undertaken:

  • port install bash-completion
  • Added

     if [ -f /opt/local/etc/bash_completion ]; then
       . /opt/local/etc/bash_completion
       echo "bash completion loaded"

    to my ~/.profile

  • port update git-core +svn +bash_completion +doc

Then I restarted the terminal, it showed me "bash completion loaded" so obviously the file exists, but the tab-completion still only works on files. Nothing magical happening after typing git and then hitting tab.

I examined /opt/local/etc/bash_completion.d/ and it gives me 149 files including git, java, man, port. I tried typing those commands and then hitting tab but nothing worked there either.

Does anyone have an idea what I did wrong? Maybe I messed up a environment variable or something. Can anyone who has bash-completion install tell me a command where it should work , like port up and then hit tab --> port upgrade. Thanks ;-)


Found another link that describes my approach: How to get git-completion.bash to work on Mac OS X?

  • Update on this two years later: Been using zsh for more than a year now, couldn't be happier. – sebastiangeiger Jul 14 '12 at 15:47

MacPorts have been breaking their bash-completion on and off for a while now. I suggest trying Fink or HomeBrew.

| improve this answer | |

I think the easiest way is to switch to zsh. There is some configuration that has to be done, but that's about it.

I added this to my ~/.zshenv file

# From http://zshwiki.org/home/examples/compquickstart
zmodload zsh/complist
autoload -U compinit && compinit

_force_rehash() {
 (( CURRENT == 1 )) && rehash
 return 1   # Because we didn't really complete anything
zstyle ':completion:::::' completer _force_rehash _complete _approximate
zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX + $#SUFFIX) / 3 )) )'
zstyle ':completion:*:descriptions' format "- %d -"
zstyle ':completion:*:corrections' format "- %d - (errors %e})"
zstyle ':completion:*:default' list-prompt '%S%M matches%s'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.(^1*)' insert-sections true
zstyle ':completion:*' menu select
zstyle ':completion:*' verbose yes
| improve this answer | |
  • 2
    zsh is nice, but the thread starter asked about bash. – yanokwa Feb 8 '10 at 16:54
  • I realize that the original question was about bash, but I threw this out as a faster way of achieving his ultimate goal without having to install anything. While zsh isn't completely backwards compatible with bash, the modifications needed convert .bashrc to .zshrc are usually pretty minor. – Mark Thalman Feb 8 '10 at 20:11
  • 1
    hmm... I can see the the advantages that zsh obviously has. While I appreciate your efforts, my intention behind posting this question was more to understand what I did wrong. Getting it to work is only secondary, it would be nice to have it but I don't really depend on it. – sebastiangeiger Feb 8 '10 at 21:53

I managed to get Bash completion up and running via Fink.

fink install bash-completion

After sourcing Fink, tab-completion works for Bash. This includes Git commands, as you described above.

| improve this answer | |

For me in tmux it worked, but in plain iTerm2 not. Solution was setting the Command to /opt/local/bin/bash -l for my used iTerm2 profile. I found the solution at https://trac.macports.org/wiki/howto/bash-completion

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.