nsvir
nsvir

Reputation: 8961

git add auto-complete filename

I am working on a git project. Since I have a lot of folder deepness, I would like to improve my auto-completion to work with filenames and not only paths.

Here is an example:

$git status                                                                                                                        1 ↵  ✹master 
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   app/src/main/java/fr/pasteque/client/BaseFlavor.java
    modified:   app/src/main/java/fr/pasteque/client/widgets/RestaurantTicketsAdapter.java

no changes added to commit (use "git add" and/or "git commit -a")

I obviously have to add a file with:

git add app/src/main/java/fr/pasteque/client/BaseFlavor.java

But I would love to be able to write: git add BaseFlavor.java

git add **/BaseFlavor.java works!

But the completion, like git add **/Base<tab>, doesn't..

Any ideas how it can works with completion ?

Thanks in advance!

Upvotes: 11

Views: 5214

Answers (3)

Nedvajz
Nedvajz

Reputation: 1029

This is very handy bash script which could help you: http://code-worrier.com/blog/autocomplete-git/

You can't use git add **/filename* but git add <tab> offers you just files and paths which are ready to commit, untracked, merge conflicts etc ..

Edit from 10.3.2020
bash script source: https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

then just edit your .bashrc as follows

if [ -f ~/pathto/.git-completion.bash ]; then
  . ~/pathto/.git-completion.bash
fi  

Upvotes: 0

Brejk
Brejk

Reputation: 454

I know it's not an exact answer to the question, but there is a very handy tool from Facebook - PathPicker - you can just select modified files you want to add.

Upvotes: 1

Arkanosis
Arkanosis

Reputation: 2334

Try git add **/Base*<tab> (notice the additional *).

Upvotes: 5

Related Questions