0

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"
     fi
    

    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 ;-)


Edit:

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

4 Answers4

1

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

Glorfindel
  • 4,158
1

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

0

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
0

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.

Dan
  • 111