Completion for git commands
I recently switched from using an Ubuntu box for the last 7 years to a Mac. I have read other posts like Switching from Ubuntu to OS X and I'm lost and What is the difference between iTerm2 and Terminal?
Why don't iTerm2 and Terminal complete the arguments for a command?
Eg. If I do gi
+Tab, it autocompletes this word to git
which is good. When I add a space and try remo
+Tab, why don't I get it autocompleted to remote
like in Ubuntu. I have to type everything manually after the word git
. Same for other commands.
Am I doing something wrong, or missing something?
(Please note that I am not talking about the cmd + ; shortcut which autocompletes previously typed entries in iTerm2.)
The easiest way to get autocompletion on OS X is to switch your shell to zsh
.
- Change default shell from bash to zsh
You can test things by running zsh
in iTerm and terminal before making the switch above. If you really want to stick with bash
you can start with these two questions:
- Is there a way to auto-complete the open command in Terminal?
- How can I make autocomplete in the shell work with case-folding?
A solution when switching from ubuntu is to use homebrew, a package manager for Mac OSX. In particular, for git
, you will have included a number of additions including bash completion. This will be true for other programs which are faliliar for developpers, like make
.
In 2 steps:
- install with
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
- Run
brew doctor
to get your path set up properly - Install git and bash completion:
brew install git bash-completion
- Add the command return in the previous step in your
.bash_profile
. - Restart your bash sessions once the new tools and configuration are written to your file system.