ok, so I needed the git autocompletion script.
I got that from this url:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
No need to worry about what directory you're in when you run this as your home directory(~
) is used with the target.
Then I added to my ~/.bash_profile
file the following 'execute if it exists' code:
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
Update: I'm making these bits of code more concise to shrink down my .bashrc
file, in this case I now use:
test -f ~/.git-completion.bash && . $_
Note: $_
means the last argument to the previous command. so . $_
means run it - "it" being .git-completion.bash
in this case
This still works on both Ubuntu and OSX and on machines without the script .git-completion.bash
script.
Now git
Tab (actually it's git
TabTab ) works like a charm!
p.s.: If this doesn't work off the bat, you may need to run chmod u+x ~/.git-completion.bash
to grant yourself the necessary permission:
chmod
is the command that modifies file permissions
u
means the user that owns the file, by default its creator, i.e. you
+
means set/activate/add a permission
x
means execute permission, i.e. the ability to run the script
You can do that by typing the following command in the terminal:
echo 'set completion-ignore-case On' >> ~/.inputrc
if you want to go back to the original behavior you have the open that file and remove the line.
The file ~/.inputrc
file deals with mapping the keyboard for specific situations. This file is the start-up file used by Readline, the input-related library used by Bash, perl and most other open source programs.
The configuration options in .inputrc are particularly useful for
customising the way Tab-completion works, e.g. with the ls command
When a program which uses the Readline library starts up, the init
file is read, and the key bindings are set.
You can find more information about the file syntax in "Bash startup files".
Best Answer
I have this in my .bashrc which works okay:
If you open up that neat script you'll see method names like
__git_checkout
. You can get completion for each of those methods using this method.Unfortunately, commands like
git pull
don't play nice when you try to tab complete the branch name (the second argument), for example given this alias:This behavior occurs: