当我连接到远程 SSH 工作区时,如何更改 VS Code 集成终端使用的 shell?
在 @Matt Bierner 的回答中补充一点。
较新版本的 vscode
现在可以让您为终端设置配置文件,并给它们自定义名称,该名称应在您的 远程设置 中引用。
CTRL+SHIFT+P -> 首选项: 打开设置 (JSON)
用户配置
...
"terminal.integrated.profiles.linux": {
"s-mann-term": {
"path": "/usr/bin/zsh"
},
"bash": {
"path": "bash"
},
"zsh": {
"path": "zsh"
},
"my-fav-term": {
"path": "fish"
}
},
"terminal.integrated.defaultProfile.linux": "s-mann-term"
...
这将使所有主机都默认使用/usr/bin/zsh
(我只是在我的配置文件中使用了path
关键字,但是您可以修改许多其他选项)。
注意:您也可以为同一shell添加多个配置文件。例如,5个不同配置的
zsh
配置文件。
CTRL+SHIFT+P -> Preferences: Open Remote Settings (SSH: az-box1)
az-box1配置
...
"terminal.integrated.defaultProfile.linux": "my-fav-term"
...
但是az-box1将默认为fish
terminal.integrated.profiles.linux
。 - thenakulchawla以上的答案都对我无效,我已经尝试了很多个月将默认的shell设置为zsh。最终有效的方法是在我的.bashrc
文件顶部添加以下内容:
if [[ "$TERM_PROGRAM" == "vscode" ]]; then
# ~/.profile is run by the login shell (this is what ssh uses)
# ~/.bashrc is run by the interactive shell (this is what vscode uses)
# Therefore, we only need to change the shell to zsh here since
# vscode will run ~/.bashrc for us.
exec zsh -l
fi
C:/program files/git/bin/bash.exe
的Windows机器时,我没有看到它被设置。 - jozxyqk
/usr/bin/zsh
,而在zsh配置文件中只使用zsh
吗? - j7skovterminal.integrated.shell.linux
,它可以工作,但是上面的解决方案却不行。 - j7skov