gpt4 book ai didi

ruby - 使用 Gemfile 进入文件夹时如何调用 RVM?

转载 作者:太空宇宙 更新时间:2023-11-03 16:25:28 25 4
gpt4 key购买 nike

我很惊讶 RVM 如何仅通过命令行导航到目录来切换支持 Gemfile 的 Ruby 版本? RVM 是否通过 shell 收到回调?任何人都可以提供这方面的指导吗?

例如这样的消息:

RVM used your Gemfile for selecting Ruby, it is all fine - Heroku does that too,
you can ignore these warnings with 'rvm rvmrc warning ignore /directory/path/to/Gemfile'.
To ignore the warning for all files run 'rvm rvmrc warning ignore allGemfiles'.

最佳答案

根据这篇文章:

https://unix.stackexchange.com/questions/21363/execute-bash-scripts-on-entering-a-directory

rvm 重新定义了 cd 命令。如果我按照 Amadan 的建议去做,我会得到:

~$ type cd
cd is a function
cd ()
{
__zsh_like_cd cd "$@"
}

这看起来像是某种别名,所以让我们试试:

~$ type __zsh_like_cd
__zsh_like_cd is a function
__zsh_like_cd ()
{
typeset __zsh_like_cd_hook;
if builtin "$@"; then
shift || true;
for __zsh_like_cd_hook in chpwd "${chpwd_functions[@]}";
do
if typeset -f "$__zsh_like_cd_hook" > /dev/null 2>&1; then
"$__zsh_like_cd_hook" "$@" || break;
fi;
done;
true;
else
return $?;
fi
}

在 zsh shell 中,chpwd 是一个钩子(Hook)函数,在当前目录发生变化时被调用。但是,我不确定为什么它可以在不提供 chpwd Hook 函数的 bash shell 中工作。阿马丹?

关于ruby - 使用 Gemfile 进入文件夹时如何调用 RVM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25561851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com