1

When I launch my first bash shell, completion for git works (git rest<TAB>->git restore). After opening a second shell within the first one, tab completion is no longer working for git, but regular file completion is still working.

The output of completion is the same in both shells (except sort order).

$ echo $0
-bash
$ complete git
$ git rest<TAB>     # <--- works
$ cd<TAB>           # <--- works
$ bash

$ echo $0
bash
$ complete git
$ git rest<TAB>     # <--- does NOT work
$ cd<TAB>           # <--- works

How do I figure out where it's going wrong?

1 Answer 1

0

This is probably because the subshell is not a login shell. I noticed from the output you posted that the first shell is a login shell (because it has a '-' as the first character) and the subshell is not a login shell.

In my bash installation the /etc/profile script sources all of the scripts under /etc/profile.d/, which includes /etc/profile.d/bash_completion.sh. But, bash does not read /etc/profile for non-login shells. I confirmed that if I start a non-login subshell (with just bash) then git completions don't work, but if I then do . /etc/profile.d/bash_completion.sh they start working.

A more general workaround may be to start the subshell as a login shell using bash --login.

1
  • Thanks, this is probably it! And yes, the lower example is started with the command bash. I can't investigate until tomorrow.
    – Moberg
    Commented Mar 19 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .