Bug 1227210 - bash-git-prompt only works for login shells
Summary: bash-git-prompt only works for login shells
Status: CONFIRMED
Alias: None
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Development (show other bugs)
Version: Current
Hardware: All openSUSE Tumbleweed
: P3 - Medium : Normal (vote)
Target Milestone: ---
Assignee: Michal Suchanek
QA Contact: E-mail List
URL: https://build.opensuse.org/package/sh...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-30 14:59 UTC by Lassi Väätämöinen
Modified: 2024-07-01 15:09 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lassi Väätämöinen 2024-06-30 14:59:39 UTC
There's a slight bug in the package, caused by the fact that /etc/profile.d/bash-git-prompt.sh is executed via /etc/profile.

Now, the bash-git-prompt works properly when you login for example on a non-graphical TTY, or via SSH (even on localhost), as here we get a login shell.

BUT when you enter to a desktop environment, and use a terminal application, bash-git-prompt __git_ps1 gets overridden by /etc/bash_completion.d/git-prompt that comes as part of git-core, as that script is executed for non-login shell by /etc/bash.bashrc

So, the sequence of issues to the problem is here:

    User comes to a login screen (e.g. SDDM)
    LOGIN -> /etc/profile gets executed
    /etc/profile.d/bash-git-prompt.sh
    PROFILEREAD=true
    Open Konsole
    /etc/bash.bashrc (and ~/.bashrc) get executed
    /etc/bash_completion.d/git-prompt is executed
    -> overrides the previously set git prompt.
    -> bash-git-prompt is only usable for login shells (sudo -i, ssh, TTY), not in graphical desktop envs.

NOTE: it does not matter if for Konsole, you set startup command as '/bin/bash --login' , since PROFILEREAD=true already (I assume), so the bash-git-prompt scripts won't get run.

IMPROVEMENT: make bash-git-propmt run in the bashrc -sequence, too.
Comment 1 Lassi Väätämöinen 2024-07-01 15:09:59 UTC
As a workaround, you of course can do this in your ~/.bashrc:

if [ -f /etc/profile.d/bash-git-prompt.sh ]
then
  source /etc/profile.d/bash-git-prompt.sh
fi

But I assume the idea for it would be to work out-of-the-box just by installing the package and starting a shell.