Search code examples
bashterminalgit-bashlinux-mint

Terminals Tab key does not autocomplete, instead attempts to run a script of mine


So I'm not sure if this is a bug or if I've changed a setting without realising.

Whenever I use tab to auto complete an argument in git-bash, it attempts to run a script of mine three times.

mike@Puter:~/workspace/project$ git bash: ./run_proxy_tests.sh: No such file or directory
bash: ./run_proxy_tests.sh: No such file or directory
bash: ./run_proxy_tests.sh: No such file or directory

I only typed in "git " and pressed tab, then it attempts to run that script. Obviously if i'm in the correct directory, it actually does run the script three times.

This only happens after typing "git ". I've tried with other commands and it works the way it's meant to.

Steps I have taken already:

1. System reboot
2. Checked ~/.bashrc && ~/.bash_aliases for an alias that may cause this
3. tried different terminals and multiplexers (tmux, tillix, terminal) (The problem exists in all)
4. sudo apt-get --remove git then reinstalled

Edit: I should also add that the same would happen if I typed "git checkout " || "git add " etc.

I can't really think of any other reason this would happen. Any ideas anyone?


Solution

  • I found the solution. Quite a rookie derp now that I think about it.

    In my ~/.bash_aliases I had an alias that was written like so:

    alias test="./run_proxy_tests.sh -p ~/workspace/project/project-proxy.linux.x86_64 -l 1"
    

    I discovered through process of elimination that if I commented it out. The problem disappeared.

    But why did this happen? Why did pressing the tab key run an alias. And only when running the git command.

    Well I looked at the git repository for git, in the "git-completion.bash" file. And found this:

        while test -n "$rest"; do
    

    No wonder it ran 3 times.

    Moral of the story: Be more explicit when naming aliases

    reference: https://github.com/git/git/blob/master/contrib/completion/git-completion.bash#L132