TaKO8Ki / frum

A little bit fast and modern Ruby version manager written in Rust
MIT License
628 stars 15 forks source link

eval "$(frum init)" appears to be broken on macos #128

Open xcodedave opened 1 year ago

xcodedave commented 1 year ago

Hi, running eval "$(frum init)" on macOS Ventura 13.1 appears to produce incorrect output. Placing eval "$(frum init)" within my ~/.zshrc file caused errors when source ~/.zshrc was run.

Running frum init directly generates the following output on my machine:

export PATH="/var/folders/qf/f11f0zsx4h76qqm9jfqyv3r00000gp/T/frum_30276_1673881668898/bin":$PATH
export FRUM_MULTISHELL_PATH="/var/folders/qf/f11f0zsx4h76qqm9jfqyv3r00000gp/T/frum_30276_1673881668898"
export FRUM_DIR="/Users/mindsetuser/.frum"
export FRUM_LOGLEVEL="info"
export FRUM_RUBY_BUILD_MIRROR="https://cache.ruby-lang.org/pub/ruby"
autoload -U add-zsh-hook
_frum_autoload_hook () {
    frum --log-level quiet local
}

add-zsh-hook chpwd _frum_autoload_hook \
    && _frum_autoload_hook

Directly running the following command fails on my machine:

add-zsh-hook chpwd _frum_autoload_hook \
    && _frum_autoload_hook

I managed to get it working by removing the trailing \ && _frum_autoload_hook from the add-zsh-hook command.

Is this a bug?

xcodedave commented 1 year ago

As a temporary workaround for my machine, this is working in my ~/.zshrc file:

FRUM_INIT_OUTPUT="$(frum init)"
FIXED_FRUM_INIT_OUTPUT=${FRUM_INIT_OUTPUT%%"\\
    && _frum_autoload_hook"}
eval "$FIXED_FRUM_INIT_OUTPUT"
TaKO8Ki commented 1 year ago

I’ll check it later.

fernandoacorreia commented 11 months ago

The problem is that frum init is generating this line in _frum_autoload_hook:

frum --log-level quiet local

It looks like the root cause is that the local subcommand is failing. Running it on the terminal fails with:

error: Can't find version in dotfiles. Please provide a version manually to the command.

The --log-level quiet option suppresses this error output but the command still fails with exit code 1.

A good fix would be a new option so that local wouldn't fail with exit code 1 when there isn't a dotfile with the version, e.g. something like frum --log-level quiet --ignore-if-not-found local.

Meanwhile this is a workaround:

eval "$(frum init | sed "s/quiet local/quiet local | true/")"