Open ChrisBaker97 opened 5 years ago
Commit 76c0683 uses the "X" FAIL_ICON prepended to the requested ruby version to indicate a missing ruby version, instead of using parentheses. I think I like this a little better, but pick whichever you prefer to merge.
There is a bug in
prompt_rbenv()
that appears when a user enters a directory where a localrbenv
setting specifies a version that is not present on the local machine:My
rbenv
hassystem
and2.6.1
installed, with2.6.1
set as the global version. However, theoh-my-zsh
custom pluginzsh-autosuggestions
has a.ruby-version
file in its project directory which specifiesruby
version2.5.3
, which is not installed.prompt_rbenv()
invokesrbenv version-name
to determine the local ruby version, which works fine when there is a local version that's installed withrbenv
or there is no local version specified. However, when a local version is specified that isn't present on the machine,rbenv version-name
displays nostdout
but does exit with a value of1
and produces thestderr
that's polluting the prompt:rbenv: version '2.5.3' is not installed...
Since it doesn't supply anystdout
,prompt_rbenv()
has no version info to publish and simply shows the ruby logo, which is unhelpful for users trying to figure out what's going on.First, this fix silences the error that's escaping into the prompt by appending
2>/dev/null
to therbenv version-name
call.Then, because
rbenv local
will always supply the local version number (even if it's not present) the logical OR function||
is used to ensure that it's called, shouldrbenv version-name
error out. It should be noted thatrbenv local
actually errors out if a local version isn't specified at all, but that's not a problem, since it will only be called if (and only if)rbenv version-name
fails, but in that case,rbenv version-name
simply returns the global version first.Similarly, this bug fix adds no additional overhead, since
rbenv local
will only be called in the relatively rare event thatrbenv version-name
first fails. However, I do agree with the discussion in #215, in that a way should probably be found to optimize or cache this function, since it is going to invoke at least one instance ofrbenv
for every prompt, even when there is no ruby project to be found and nothing additional is displayed on the prompt to atone for it.Finally, I thought it would be nice if there were also an indication that the requested
ruby
version wasn't installed—rather than just printing it as if everything was normal—so I enclosed the version number in quotes in that instance. It could be a future enhancement to include a warning triangle ⚠️ icon, or change the colors, or something else, but I didn't bother here.So, after the patch is applied, here's the new behavior: