Search code examples
bashgitgit-bashdotfiles

Git PS1 & Bash Subshell Issue (Windows vs Linux)


After trawling google, the bash manpage and other questions here on SO, I have found similar posts but I have failed to determine the cause of this particular issue.

I have installed git-prompt.sh locally. All is good in the bash --login shell. It really is a good thing on both Windows and Linux.

However, as soon as I execute a bash subshell (e.g so that I can temporarily modify my environment etc) I get the error:

$ ... <in/out of repos and all good>
$ bash
bash: __git_ps1: command not found

This problem does not happen on Windows.

Something to note is that I have my dotfiles setup via git. For this reason I can run my configuration on both windows and linux and they both have exactly the same git-prompt.sh file.

  • Windows 10 git==2.19.2.windows.1 bash==4.4.19(2)-release
  • Arch Linux git==2.19.2 bash==4.4.23(1)-release

Both are fresh OS installs.

My best guess so far is that different shell interaction semantics are executed when operating under windows rather than linux. I have experimented with various bash invocations (--login, --norc ie so I can manually set stuff) etc. There are 3 reasons for this suspicion:

  1. This error looks like the kind of error we get when we forget to export a variable/parameter.
  2. Both "/etc/profile.d" sources are different on each platform. Some contain git support, and perhaps this is contributing to the previous reason.
  3. My bash-fu was good ~10+ years ago, now I am rusty.

One thing I know for sure is that the first login bash ("sub")shell works perfectly on both platforms.

Any ideas, feedback or pointers?

Thanks,

Matt


Solution

  • Solved. The issue was due to a comibination of (2) above (i.e. indirect different versions of the prompt) and bad quoting of a regular expression by myself in a guard.

    Thank you for your help.