Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash update 4.3.046 breaks PS1 environment variable #653

Closed
ghost opened this issue Jul 14, 2016 · 7 comments
Closed

Bash update 4.3.046 breaks PS1 environment variable #653

ghost opened this issue Jul 14, 2016 · 7 comments

Comments

@ghost
Copy link

ghost commented Jul 14, 2016

After updating bash, user's prompt is set to PS1=\s-\v\$ whereas previously it was set to PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$".
Fairly easy to fix if you know where to look although new users may struggle.

What else may have been affected by the update?
Compiling in the Win64 MinGW-w64 shell appears to still work fine but it's not clear what files the bash update changed and how they changed.
Would this have broken prompts for people who had customised theirs?

@ghost
Copy link
Author

ghost commented Jul 14, 2016

Also, workaround to get prompt back to how it was is to run:

echo "export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$'" >> .bashrc

which will add the prompt to the end of your .bashrc file. This is found at C:\msys64\home[username] assuming you installed the 64bit version in the default directory.

@ghost
Copy link
Author

ghost commented Jul 14, 2016

So, there was a change in /etc/bash.bashrc where this:

# Set a default prompt of: user@host, MSYSTEM variable, and current_directory
PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$ '

was changed to this:

# Warnings
unset _warning_found
for _warning_prefix in '' ${MINGW_PREFIX}; do
    for _warning_file in ${_warning_prefix}/etc/profile.d/*.warning{.once,}; do
        test -f "${_warning_file}" || continue
        _warning="$(command sed 's/^/\t\t/' "${_warning_file}" 2>/dev/null)"
        if test -n "${_warning}"; then
            if test -z "${_warning_found}"; then
                _warning_found='true'
                echo
            fi
            if test -t 1
                then printf "\t\e[1;33mwarning:\e[0m\n${_warning}\n\n"
                else printf "\twarning:\n${_warning}\n\n"
            fi
        fi
        [[ "${_warning_file}" = *.once ]] && rm -f "${_warning_file}"
    done
done
unset _warning_found
unset _warning_prefix
unset _warning_file
unset _warning

# If MSYS2_PS1 is set, use that as default PS1;
# if a PS1 is already set, use that;
# otherwise set a default prompt
# of user@host, MSYSTEM variable, and current_directory
if test -n "${MSYS2_PS1}"
    then PS1="${MSYS2_PS1}"
    elif test -z "${PS1}"
        then PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n\$ '
fi

@PhilipOakley
Copy link
Contributor

@ukhf-jm Thank you for the analysis. I authoured the minor fix #651 to a previous fix that broke the Git for Windows SDK's bash title bar settings part of the PS1. (more details on that link)

Any input on putting together a proper fix that covers typical user settings would be gratefully recieved (I'm an engineer who mainly works on Windows so the fine details of bash set ups is not something I normally deal with ;-)

@yuriks
Copy link

yuriks commented Jul 14, 2016

I'm also affected by this. It seems like this change was originally made to support Git4Windows settings its own PS1. However, where was that previous prompt set from? It shouldn't be possible for anything to run before the system-wide profile files. Is Git for Windows setting the PS1 via an exported environment variable?

@PhilipOakley
Copy link
Contributor

@yuriks, No (original==G4W?). This (my small #651) change was because the previous patch 6e6310d had broken the G4W SDK. These two commits must be taken as a pair, and each of the different backstories surfaced and considered, including @renatosilva's original rationale (the logic back then may have been incomplete).

@ghost
Copy link
Author

ghost commented Jul 15, 2016

Just tried a fresh install again and can confirm prompt is as expected after updating bash. Thank you @Alexpux , @Karlson2k and @PhilipOakley

@Karlson2k
Copy link
Contributor

@ukhf-jm Thanks for report!

dscho added a commit to dscho/MSYS2-packages that referenced this issue Jan 31, 2022
In 73e06b9 (bash.bashrc: Update PS1 if PS1 wasn't exported. Closes
 msys2#653, 2016-07-14), we updated `/etc/bash.bashrc` to avoid overriding
`PS1`, but the way it was done requires `cut.exe` to be in the `PATH`.

Now, while _most_ of the time we're running inside a login Bash where
the `PATH` has been appropriately modified, sometimes we don't. In that
case, `cut.exe` is not in the `PATH`.

We should not spawn a new process, anyway, as spawning processes is
really expensive in the MSYS2 runtime because of all the contortions
necessary to emulate the POSIX syscall `fork()`.

Let's just avoid that extra process by using `case`, which is a Bash
built-in and therefore won't cost much time to run.

This fixes git-for-windows/git#3652

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/MSYS2-packages that referenced this issue Jan 31, 2022
In 73e06b9 (bash.bashrc: Update PS1 if PS1 wasn't exported. Closes
 msys2#653, 2016-07-14), we updated `/etc/bash.bashrc` to avoid overriding
`PS1`, but the way it was done requires `cut.exe` to be in the `PATH`.

Now, while _most_ of the time we're running inside a login Bash where
the `PATH` has been appropriately modified, sometimes we don't. In that
case, `cut.exe` is not in the `PATH`.

We should not spawn a new process, anyway, as spawning processes is
really expensive in the MSYS2 runtime because of all the contortions
necessary to emulate the POSIX syscall `fork()`.

Let's just avoid that extra process by using `case`, which is a Bash
built-in and therefore won't cost much time to run.

This fixes git-for-windows/git#3652

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/MSYS2-packages that referenced this issue Feb 1, 2022
In 73e06b9 (bash.bashrc: Update PS1 if PS1 wasn't exported. Closes
 msys2#653, 2016-07-14), we updated `/etc/bash.bashrc` to avoid overriding
`PS1`, but the way it was done requires `cut.exe` to be in the `PATH`.

Now, while _most_ of the time we're running inside a login Bash where
the `PATH` has been appropriately modified, sometimes we don't. In that
case, `cut.exe` is not in the `PATH`.

We should not spawn a new process, anyway, as spawning processes is
really expensive in the MSYS2 runtime because of all the contortions
necessary to emulate the POSIX syscall `fork()`.

Let's just avoid that extra process by using `case`, which is a Bash
built-in and therefore won't cost much time to run.

This fixes git-for-windows/git#3652

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants