diff options
author | Nick Young <nick@nickwb.net> | 2019-09-05 00:23:31 +1000 |
---|---|---|
committer | Kevin Song <chipbuster@users.noreply.github.com> | 2019-09-04 09:23:31 -0500 |
commit | 5a0f269d85c3bc8a64aa6ee1f3cea4d072d070cb (patch) | |
tree | 8ce0ec871d5c7d55bd998e01fa2bdf0251e530a1 /src | |
parent | 789d504a447fd1de4b7b97981d87d8bfb6e9e657 (diff) |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/init.rs | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/src/init.rs b/src/init.rs index 41aaac046..92390c755 100644 --- a/src/init.rs +++ b/src/init.rs @@ -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 |