For years now, I've had a working recipe to enable bash autocompletion for git on my Mac. Recently that broke due to a packaging change with Xcode's CommandLineTools. So, let's take a moment to review how this all works, and how we can get it working (again).
Quick background on bashrc files
bashrc files are environment configuration scripts that Bash includes when it starts. You can use them to customize your CLI experience.
However, the single
~/.bashrc file can get unmanageable quickly. So just like any other piece of software, we'd like to template things and break the problem into smaller chunks.
dotfiles GitHub repo includes the collection of
.bashrc template files I use on a day-to-day basis:
jamesonwilliams / dotfiles
Jameson's . (dot) files for Linux
Jameson's . (dot) files for UNIX and Linux family command-line environments.
One goal of these dot files is to converge on a similar experience across some different UNIX/Linux systems that we encounter in the wild:
- Amazon Linux
- Mac OS X
To install the dot files for a particular user on your system, do:
git clone https://github.com/jamesonwilliams/dotfiles.git ./dotfiles/install.sh
Basically, they work as follows.
~/.bash_profileis the hook used by Mac OS X to start loading your Bash customizations. Mine does nothing other than call
~/.bashrcitself contains no real logic, it just sources a bunch of template files that handle specific sub-problems.
- One of these template files is called
~/.bashrc.darwin, and it includes some fixes for Mac-specific quirks. Stuff that's generally useful on Linux or other UNIX flavors doesn't go into this file.
How it used to work on Mac OS X
One of the quirks of using OS X is that tab completion with git doesn't work out of the box. So for years, I've had a little bit of configuration to handle this case:
# In ~/.bashrc.darwin cli_tools='/Library/Developer/CommandLineTools' git_core="$cli_tools/usr/share/git-core" git_completion="$git_core/git-completion.bash" [ -x "$(which git)" ] && \ [ -f "$git_completion" ] && \ source "$git_completion"
If git is installed and the git completion file can be found, we source it into the environment.
How it works now
git-completion.bash file disappeared from the CommandLineTools install, and so my tab completion stopped working.
Turns out it now lives here:
So all that's needed is to update our pathing for
# In ~/.bashrc.darwin xcode_dev_dir='/Applications/Xcode.app/Contents/Developer' git_core="$xcode_dev_dir/usr/share/git-core" git_completion="$git_core/git-completion.bash" [ -x "$(which git)" ] && \ [ -f "$git_completion" ] && \ source "$git_completion"
Save the file, reboot your laptop, and profit. Happy git-ing.
Top comments (0)