Jam*_*son 5 shell rvm visual-studio-code
我使用 RVM 在基于 Mac 的开发环境中更改 Ruby 版本。
-l
在 Visual Studio Code 中,当我打开常规终端选项卡时,我会根据标准默认配置进入带有选项的 bash 登录 shell ,如下所示:
// VSCode default settings
{
"terminal.integrated.shell.osx": "/bin/bash",
"terminal.integrated.shellArgs.osx": [
"-l"
]
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,从 VSCode 终端手动执行的 RVM 命令为我提供了该项目预期的 ruby 版本。
$ rvm list
ruby-2.0.0-p648 [ x86_64 ]
ruby-2.1.10 [ x86_64 ]
ruby-2.1.5 [ x86_64 ]
ruby-2.2.10 [ x86_64 ]
ruby-2.2.5 [ x86_64 ]
ruby-2.3.0 [ x86_64 ]
* ruby-2.3.1 [ x86_64 ]
=> ruby-2.3.7 [ x86_64 ]
# => - current
# =* - current && default
# * - default
Run Code Online (Sandbox Code Playgroud)
然而,当我设置一个.vscode/tasks.json
文件来执行相同的命令时,Ruby 版本不是正确的版本,而是系统上的默认版本。此外,我无法实际使用rvm use
来切换版本(请参阅下面的错误消息)
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Check for RVM",
"type": "shell",
"command": "rvm list && rvm use 2.3.7",
"group": {
"kind": "test",
"isDefault": true
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
任务执行的输出,包含有关没有正确登录 shell 的错误消息。
> Executing task: rvm list && rvm use 2.3.7 <
ruby-2.0.0-p648 [ x86_64 ]
ruby-2.1.10 [ x86_64 ]
ruby-2.1.5 [ x86_64 ]
ruby-2.2.10 [ x86_64 ]
ruby-2.2.5 [ x86_64 ]
ruby-2.3.0 [ x86_64 ]
=* ruby-2.3.1 [ x86_64 ]
ruby-2.3.7 [ x86_64 ]
# => - current
# =* - current && default
# * - default
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.
Terminal will be reused by tasks, press any key to close it.
Run Code Online (Sandbox Code Playgroud)
我什至尝试专门添加-l
bash 命令选项作为任务配置中的参数,但这不起作用。
"options": {
"shell": {
"args": "-l"
}
}
Run Code Online (Sandbox Code Playgroud)
我的理解是,读完这个问题后,终端 shell 配置和任务 shell 配置是相同的,那么终端 shell 和任务 shell 之间是否存在我所缺少的其他潜在不一致?如果不是,那么 RVM 是如何阻止它在 Task shell 中工作的呢?
RVM 会覆盖“cd”命令来检测 .ruby-version 和 .ruby-gemset 文件并自动设置您的环境。新启动的 vscode 终端不会触发该事件。它仅使用 vscode 启动时的默认或当前设置,而不是您在 .ruby* 文件中定义的设置。
cd $PWD
所以我通常在 vscode 中启动新终端时运行。
在tasks.json中定义rake任务时,我的命令行如下所示:
{
"label": "rake db:migrate",
"type": "shell",
"command": "cd $PWD; rake db:migrate",
"problemMatcher": []
},
Run Code Online (Sandbox Code Playgroud)
请注意cd $PWD
命令行前面的内容,以挂钩 rvm。
这很糟糕。但到目前为止它对我有用。
我怀疑对 rvm/.ruby-gemset/.ruby-version 的不了解也会阻止 vscode 自动检测 Ruby 插件应该执行的 rake 任务,如此处所述https://medium.com/hack-visual -studio-code/rake-task-auto-detection-in-vscode-ce548488755e。因此,我想通过 vscode 任务运行的任何 rake 任务都必须由我以这种方式手动定义。
希望这可以帮助。
归档时间: |
|
查看次数: |
2262 次 |
最近记录: |