如何为 VS Code SSH Remote 配置不同的 shell?
How do I configure a different shell for a VS Code SSH Remote?
当我连接到 remote ssh workspace 时,如何更改用于 VS Code 集成终端的 shell?
您可以使用远程设置为每个主机更改 shell。为此,请在 VS Code 中打开远程工作区并 运行 Open Remote settings
命令:
将 terminal.integrated.shell.linux
设置为指向您的 shell 并保存文件:
"terminal.integrated.shell.linux": "/usr/bin/fish"
远程设置适用于您在给定主机上打开的所有工作区,但必须为您连接的每个主机进行配置。
添加到@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
键,但有一堆 other options 您可以修改)
NOTE: You can add multiple profiles for the same shell as well. For example, 5 differently configured zsh
profiles.
CTRL+SHIFT+P -> Preferences: Open Remote Settings (SSH: az-box1)
az-box1 配置
...
"terminal.integrated.defaultProfile.linux": "my-fav-term"
...
但是az-box1会默认为fish
None 上面的答案对我有用,我一直试图让默认的 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
当我连接到 remote ssh workspace 时,如何更改用于 VS Code 集成终端的 shell?
您可以使用远程设置为每个主机更改 shell。为此,请在 VS Code 中打开远程工作区并 运行 Open Remote settings
命令:
将 terminal.integrated.shell.linux
设置为指向您的 shell 并保存文件:
"terminal.integrated.shell.linux": "/usr/bin/fish"
远程设置适用于您在给定主机上打开的所有工作区,但必须为您连接的每个主机进行配置。
添加到@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
键,但有一堆 other options 您可以修改)
NOTE: You can add multiple profiles for the same shell as well. For example, 5 differently configured
zsh
profiles.
CTRL+SHIFT+P -> Preferences: Open Remote Settings (SSH: az-box1)
az-box1 配置
...
"terminal.integrated.defaultProfile.linux": "my-fav-term"
...
但是az-box1会默认为fish
None 上面的答案对我有用,我一直试图让默认的 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