jimeh / git-aware-prompt

Display current Git branch name in your terminal prompt when in a Git working directory.
Creative Commons Zero v1.0 Universal
2.15k stars 340 forks source link

Call from .bashrc instead of .bash_profile? #43

Open jpmv27 opened 8 years ago

jpmv27 commented 8 years ago

The instructions say to install in .bash_profile. If you do this, then find_git_branch and find_git_dirty functions aren't defined in any bash/xterm started from a login shell, so git_branch and git_dirty variables don't get updated.

I think the instructions should be changed to recommend installation in .bashrc instead

lethosor commented 8 years ago

This depends on whether your terminal emulator starts login shells (which load .bash_profile) or non-login shells (which load .bashrc) by default. Both .bash_profile and .bashrc are already mentioned in the readme.

See also #24, #31

jpmv27 commented 8 years ago

True, and I have been using git-aware-prompt for a while without noticing the problem because I was always ssh'ing to a Linux VM, so every shell was a login shell. But I tripped over this when I started using it on a box where I am logged into KDE and then running Konsole, which is not run as a login shell. Then it doesn't work any more. Anyway, .bash_profile should source .bashrc, so running git-aware-prompt should always work if placed in .bashrc, may not always work if placed in .bash_profile. I'm suggesting it would be "better" to suggest .bashrc as the first choice.

lethosor commented 8 years ago

While it is a good idea to source .bashrc from .bash_profile, or link one to the other, I doubt that everyone who uses git-aware-prompt has done that, given previously-reported issues. Switching the order in the readme is bound to lead to more confusion and issues like "Change .bashrc to .bash_profile?".

I think the best solution is to mention that different environments may read from different files when starting a shell, so people either need to figure out which one to add git-aware-prompt to or ensure that it is set up regardless of which file is loaded (e.g. sourcing one file from the other, linking one file to the other, etc.).

jpmv27 commented 8 years ago

What you propose is a good compromise. It seems that in all the environments I'm currently using (Ubuntu 12.04 and later, Fedora 23 and later) that .bash_profile sources .bashrc, but I don't really know how widespread that is. I do recall that in the (distant) past, that was something that I had to configure myself. Thanks

lethosor commented 8 years ago

On a fresh installation of Ubuntu 16.04, ~/.bash_profile does not exist, but ~/.profile does (and sources .bashrc when run by bash):

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
...

Neither of these exist on OS X, however, and it probably varies on other Linux distros.

I'll look at updating the readme if I get a chance, although this project hasn't been especially active lately, so I don't know when it'll get merged.

joeytwiddle commented 8 years ago

I believe the owner is more likely to merge documentation than code.

This popular answer recommends that .bash_profile should always source .bashrc.

Perhaps the installation instructions should recommend using .bashrc but also recommend ensuring that .bash_profile sources .bashrc, for users with "misconfigured" files.

CentOS has no .profile but always sources .bashrc from .bash_profile. Debian does the same as Ubuntu in .profile (see previous comment).

(By the way, we could even detect an interactive shell like this.)