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?

sebastiangeiger
  • 221
  • 2
  • 7

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,089
  • 8
  • 24
  • 37
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

michalzuber
  • 167
  • 1
  • 5
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
Mark Thalman
  • 978
  • 10
  • 15
  • 2
    zsh is nice, but the thread starter asked about bash. – yanokwa Feb 08 '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 08 '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 08 '10 at 21:53
  • "Use another tool" is not an answer to "how do I do something with the tool I have." Sometimes, the option to switch to another tool is available, but sometimes it is not. – John Anderson Aug 18 '20 at 14:33
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
  • 5