当我连接到远程 ssh 工作区时,如何更改 VS Code 集成终端使用的 shell?
添加@Matt Bierner 的答案。
较新版本的
vscode
现在可以让您为终端设置配置文件并为其提供自定义名称,并且该名称应该在您的远程设置中引用。
CTRL+SHIFT+P ->
Preferences: Open Settings (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
以上答案都不适合我,几个月来我一直在尝试将默认 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
这对我有用
{
"terminal.integrated.defaultProfile.linux": "fish",
"terminal.integrated.profiles.linux" : {
"fish": {
"path": "/usr/bin/fish",
"args": ["-l"]
},
"bash": {
"path" : "..."
},
"zsh" : {
...
}
}
}