1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-26 03:27:30 +00:00

fix: Be more restrictive with bash init fallback (#278)

This should improve compatibility with "Git Bash" with Git for Windows by
using psub+source init for all bash shells v4.1 and newer.
This commit is contained in:
Nick Young 2019-09-05 00:23:31 +10:00 committed by Kevin Song
parent 789d504a44
commit 5a0f269d85

View File

@ -32,12 +32,40 @@ pub fn init_stub(shell_name: &str) -> io::Result<()> {
let setup_stub = match shell_basename {
Some("bash") => {
/* This *should* look like the zsh function, but bash 3.2 (MacOS default shell)
does not support using source with process substitution, so we use this
workaround from https://stackoverflow.com/a/32596626 */
/*
* The standard bash bootstrap is:
* `source <(starship init bash --print-full-init)`
*
* Unfortunately there is an issue with bash 3.2 (the MacOS
* default) which prevents this from working. It does not support
* `source` with process substitution.
*
* There are more details here: https://stackoverflow.com/a/32596626
*
* The workaround for MacOS is to use the `/dev/stdin` trick you
* see below. However, there are some systems with emulated POSIX
* environments which do not support `/dev/stdin`. For example,
* `Git Bash` within `Git for Windows and `Termux` on Android.
*
* Fortunately, these apps ship with recent-ish versions of bash.
* Git Bash is currently shipping bash 4.4 and Termux is shipping
* bash 5.0.
*
* Some testing has suggested that bash 4.0 is also incompatible
* with the standard bootstrap, whereas bash 4.1 appears to be
* consistently compatible.
*
* The upshot of all of this, is that we will use the standard
* bootstrap whenever the bash version is 4.1 or higher. Otherwise,
* we fall back to the `/dev/stdin` solution.
*
* More background can be found in these pull requests:
* https://github.com/starship/starship/pull/241
* https://github.com/starship/starship/pull/278
*/
let script = {
format!(
r#"if [ "${{BASH_VERSINFO[0]}}" -gt 4 ]
r#"if [ "${{BASH_VERSINFO[0]}}" -gt 4 ] || ([ "${{BASH_VERSINFO[0]}}" -eq 4 ] && [ "${{BASH_VERSINFO[1]}}" -ge 1 ])
then
source <("{}" init bash --print-full-init)
else