Homebrew’s `git` not using completion

后端 未结 18 1858
盖世英雄少女心
盖世英雄少女心 2020-12-22 16:25

When using OSX’s git, after I modify a file I can simply do git commit , and that’ll auto complete the file’s name to the one that was modified. Howe

相关标签:
18条回答
  • 2020-12-22 16:36

    For me , I had to put

    source $(brew --prefix)/etc/bash_completion
    

    into .bashrc (not .bash_profile) to get this to work.

    ".bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells" -- from What is the difference between .bash_profile and .bashrc? It appears to me that MacOS Sierra doesn't execute .bash_profile when opening a new terminal window, only .bashrc.

    I wouldn't put it in _bash_profile, because then I'd have to reboot/logout for updates to take effect.

    0 讨论(0)
  • 2020-12-22 16:37

    I had the same issue and even found this post this morning. I fixed the issue by updating brew with brew update and then reinstalling git with brew reinstall git.

    I was then notified of another file that is blocking the homebrew linking process, in my case it was /usr/local/share/zsh/site-functions/git-completion.bash. Removing the file and running brew link git solved the issue. Guessing it was just a bad recipe version we stumbled upon.

    0 讨论(0)
  • 2020-12-22 16:37

    In 2019, using Bash v5, you do not need to explicitly source the git bash completion script in your .bash_profile or .bashrc

    1. Ensure you have the following two lines in your .bashrc
    export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
    [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
    
    1. Download the git bash completion script (https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash) and save it to /usr/local/etc/bash_completion.d/ as git

    That's it! Bash will automatically pick up the git completion file and enable completion.


    Side Note: I recommend putting all these changes in .bashrc as this ensures that when you drop into an interactive shell (ie. from pipenv shell), completions will get loaded correctly as bash will source .bashrc and NOT .bash_profile.

    0 讨论(0)
  • 2020-12-22 16:39

    Step 1: Download auto completion script:

    cd ~
    curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
    

    Step 2: Update .bash_profile and .bashrc

    echo "source ~/git-completion.bash" >> .bash_profile
    

    Via https://www.anintegratedworld.com/git-tab-autocomplete-on-osx-10-11-el-capitan/

    If above does not work, try https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion

    0 讨论(0)
  • 2020-12-22 16:39

    This worked for me in Mojave (OSX 10.14.1):

    brew install bash-completion
    

    Then add the following line to your ~/.bash_profile:

    [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
    
    0 讨论(0)
  • 2020-12-22 16:39

    It may have something to do with libedit being used instead of readline in Lion.

    Try installing readline before git.

    brew install readline
    
    0 讨论(0)
提交回复
热议问题