filesystem(bashrc): avoid spawning an external process

In 73e06b9d4c (bash.bashrc: Update PS1 if PS1 wasn't exported. Closes
 #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 https://github.com/git-for-windows/git/issues/3652

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2022-01-31 14:11:15 +01:00
parent ee5ab28467
commit 0c3ca441d7
2 changed files with 7 additions and 3 deletions

View File

@ -5,7 +5,7 @@
pkgname=filesystem
pkgver=2022.01
pkgrel=1
pkgrel=2
pkgdesc='Base filesystem'
arch=('i686' 'x86_64')
license=('BSD')
@ -53,7 +53,7 @@ source=('bash.bash_logout'
'redirect-config.site'
'os-release')
sha256sums=('742a7d66b7a5ebd2b8461728c5b44a46b2305fd2116208eecae5f45828938ea0'
'dfb0a5c21b1b1dcec942f556fe32967bd78207c47ff28093837a37d2ed457e92'
'36d4affa25606c87e70c42a5fe2294aa7898fb54f93a27910fb55224f4d6588a'
'99eae6e37081edd73b399009c85f4a67a0c14481241ee4937ab45c4178b540fb'
'69e62980bd853bc67194c3cd0b3547b35ab5b2fc7237d70f15617196685bf287'
'4330edf340394d0dae50afb04ac2a621f106fe67fb634ec81c4bfb98be2a1eb5'

View File

@ -54,8 +54,12 @@ if [[ -n "$(command -v getent)" ]] && id -G | grep -q "$(getent -w group 'S-1-16
then _ps1_symbol='\[\e[1m\]#\[\e[0m\]'
else _ps1_symbol='\$'
fi
[[ $(declare -p PS1 2>/dev/null | cut -c 1-11) = 'declare -x ' ]] || \
case "$(declare -p PS1 2>/dev/null)" in
'declare -x '*) ;; # okay
*)
export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[35m\]$MSYSTEM\[\e[0m\] \[\e[33m\]\w\[\e[0m\]\n'"${_ps1_symbol}"' '
;;
esac
unset _ps1_symbol
# Uncomment to use the terminal colours set in DIR_COLORS