Open sobrinho opened 3 years ago
Long ago chruby used to use precmd_functions
(issue #40), but those do not execute when in non-interactive mode (ex: zsh -c "cd path/to/file && ruby ..."
). Thus I switched to preexec_functions
which will execute in both interactive and non-interactive sessions. 92934220a66f96ed3a1e3328d3d389459207b9ba
Maybe we should detect non-interactive mode and fallback to using preexec_functions
, otherwise use precmd_functions
?
Looks like a good approach!
While that I'm calling chruby_auto
on .zshrc
and it is working as expected, maybe we could call chruby_auto
when sourcing the auto file to avoid the machinery?
@sobrinho note that chruby_auto
also has to catch multiple cd
s in non-interactive mode (as well as when a .ruby-version
file is created by the previous command), such as when running a shell script under zsh from a cron job.
Also, we should make sure that any changes to chruby_auto
zsh support do not introduce deviations in how chruby_auto
behaves under bash.
@postmodern Here's another use case.
I've tripped over this issue as well trying to add the current Ruby version to the iTerm status bar:
In case someone is interested in how to do this:
iterm2_print_user_vars() { iterm2_set_user_var ruby_version "$RUBY_VERSION" }
\(user.ruby_version)
.Currently, cd
ing into a directory which switches the Ruby won't update the status bar until the next command (preexec), but it works fine when using precmd instead. I guess, a solution along the lines of what you suggested above would do the trick.
I'm adding a call to chruby_auto
in my zsh prompt precmd()
. Downside is I think I'm now running chruby_auto
again when I execute a command as well so it will run twice generally.
Agree that a good solution would be to use precmd
for interactive and prexec
for non.
I'm generally only running bash in scripts - does Bash also have the same problem?
Description
preexec_functions does not run early enough for chruby work soon enough for RPS1.
Another way of fixing is calling
chruby_auto
on~/.zshrc
but precmd_functions seems more appropriate. Maybe?Steps To Reproduce
Steps to reproduce the bug:
.ruby-version
with any versionexport RPS1="%F{240}host %F{255}%m %F{240}pwd %F{255}%1~ %F{240}vcs %F{255}\${vcs_info_msg_0_:-ッ} %F{240}ruby %F{255}\$(chruby_prompt_info || echo ッ) %F{240}node %F{255}\$(node -v || echo "ッ")"
Expected Behavior
Actual Behavior
Environment