Homebrew’s `git` not using completion

后端 未结 18 2011
盖世英雄少女心
盖世英雄少女心 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: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.

提交回复
热议问题