如何为 VS Code SSH 远程配置不同的 shell?

问题描述 投票:0回答:4

当我连接到远程 ssh 工作区时,如何更改 VS Code 集成终端使用的 shell?

ssh visual-studio-code vscode-remote
4个回答
20
投票

添加@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


13
投票

您可以使用远程设置来更改每个主机的外壳。为此,请在 VS Code 中打开远程工作区并运行

Open Remote settings
命令:

设置

terminal.integrated.shell.linux
指向您的 shell 并保存文件:

"terminal.integrated.shell.linux": "/usr/bin/fish"

远程设置适用于您在给定主机上打开的所有工作区,但必须为您连接到的每个主机进行配置。


2
投票

以上答案都不适合我,几个月来我一直在尝试将默认 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

0
投票

这对我有用

{
    "terminal.integrated.defaultProfile.linux": "fish",
    "terminal.integrated.profiles.linux" : {
        "fish": {
            "path": "/usr/bin/fish",
            "args": ["-l"]
        },
        "bash": {
           "path" : "..."
        },
        "zsh" : {
            ...
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.