如何使用wt.exe启动ssh并保持终端颜色

huangapple go评论66阅读模式
英文:

How to start ssh with wt.exe and keep terminal colors

问题

I have this shortcut

C:\Users\David\AppData\Local\Microsoft\WindowsApps\wt.exe --window 0 -p "Windows PowerShell" C:\Program Files\PowerShell\7\pwsh.exe -noExit -Command "ssh webdev"

It works fine but the terminal opened doesn't have colors.

This is regular terminal:

如何使用wt.exe启动ssh并保持终端颜色

This is the shortcut:

如何使用wt.exe启动ssh并保持终端颜色

A video of me opening an ssh connection in different ways.

https://files.catbox.moe/vskxx0.webm

Shortcut 1: "C:\Program Files\PowerShell\7\pwsh.exe" -Command "ssh webdev"

Shortcut 2: wt.exe "C:\Program Files\PowerShell\7\pwsh.exe" -Command "ssh webdev"

I'd like to use wt.exe because I like being able to easily open a new tab.

Update

I found in C:\Users\David\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json that the colorScheme used is the default one 'Solarized Dark' instead of the 'Windows PowerShell 7' profile's 'One Half Dark'.

Even if specified in the shortcut

C:\Users\David\AppData\Local\Microsoft\WindowsApps\wt.exe -p "Windows PowerShell 7" "C:\Program Files\PowerShell\7\pwsh.exe"

Fixed

-p "Windows Powershell 7"
SHOULD HAVE BEEN
-p "Windows PowerShell 7"

英文:

I have this shortcut

C:\Users\David\AppData\Local\Microsoft\WindowsApps\wt.exe --window 0 -p "Windows Powershell" C:\Program Files\PowerShell\7\pwsh.exe -noExit -Command "ssh webdev"

It works fine but the terminal opened doesn't have colors.

This is regular terminal:

如何使用wt.exe启动ssh并保持终端颜色

This is the shortcut:

如何使用wt.exe启动ssh并保持终端颜色

A video of me opening an ssh connection in different ways.

https://files.catbox.moe/vskxx0.webm

Shortcut 1: "C:\Program Files\PowerShell\7\pwsh.exe" -Command "ssh webdev"

Shortcut 2: wt.exe "C:\Program Files\PowerShell\7\pwsh.exe" -Command "ssh webdev"

I'd like to use wt.exe because I like being able to easily open a new tab.

Update

I found in C:\Users\David\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json that the colorScheme used is the default one 'Solarized Dark' instead of the 'Windows PowerShell 7' profile's 'One Half Dark'.

Even if specified in the shortcut

C:\Users\David\AppData\Local\Microsoft\WindowsApps\wt.exe -p "Windows Powershell 7" "C:\Program Files\PowerShell\7\pwsh.exe" -Command "ssh webdev"

{
    "$help": "https://aka.ms/terminal-documentation",
    "$schema": "https://aka.ms/terminal-profiles-schema",
    "actions": 
    [
        {
            "command": "find",
            "keys": "ctrl+shift+f"
        },
        {
            "command": "paste",
            "keys": "ctrl+v"
        },
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "keys": "ctrl+c"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "keys": "alt+shift+d"
        }
    ],
    "copyFormatting": "none",
    "copyOnSelect": false,
    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "profiles": 
    {
        "defaults": 
        {
            "colorScheme": "Solarized Dark",
            "font": 
            {
                "face": "FiraCode Nerd Font Mono"
            }
        },
        "list": 
        [
            {
                "colorScheme": "One Half Dark",
                "commandline": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell 7"
            },
            {
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "S\u00edmbolo del sistema"
            },
            {
                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
                "hidden": false,
                "name": "Ubuntu-18.04",
                "source": "Windows.Terminal.Wsl"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "guid": "{cc1103f1-07a6-5722-a92c-731a1a864d7f}",
                "hidden": false,
                "name": "Developer Command Prompt for VS 2022",
                "source": "Windows.Terminal.VisualStudio"
            },
            {
                "guid": "{6501f08f-1c83-5423-afd5-5e1b828bff9a}",
                "hidden": false,
                "name": "Developer PowerShell for VS 2022",
                "source": "Windows.Terminal.VisualStudio"
            },
            {
                "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
                "hidden": false,
                "name": "PowerShell",
                "source": "Windows.Terminal.PowershellCore"
            }
        ]
    },
    "schemes": 
    [
        {
            "background": "#0C0C0C",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#012456",
            "black": "#0C0C0C",
            "blue": "#0037DA",
            "brightBlack": "#767676",
            "brightBlue": "#3B78FF",
            "brightCyan": "#61D6D6",
            "brightGreen": "#16C60C",
            "brightPurple": "#B4009E",
            "brightRed": "#E74856",
            "brightWhite": "#F2F2F2",
            "brightYellow": "#F9F1A5",
            "cursorColor": "#FFFFFF",
            "cyan": "#3A96DD",
            "foreground": "#CCCCCC",
            "green": "#13A10E",
            "name": "Campbell Powershell",
            "purple": "#881798",
            "red": "#C50F1F",
            "selectionBackground": "#FFFFFF",
            "white": "#CCCCCC",
            "yellow": "#C19C00"
        },
        {
            "background": "#282C34",
            "black": "#282C34",
            "blue": "#61AFEF",
            "brightBlack": "#5A6374",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B6C2",
            "brightGreen": "#98C379",
            "brightPurple": "#C678DD",
            "brightRed": "#E06C75",
            "brightWhite": "#DCDFE4",
            "brightYellow": "#E5C07B",
            "cursorColor": "#FFFFFF",
            "cyan": "#56B6C2",
            "foreground": "#DCDFE4",
            "green": "#98C379",
            "name": "One Half Dark",
            "purple": "#C678DD",
            "red": "#E06C75",
            "selectionBackground": "#FFFFFF",
            "white": "#DCDFE4",
            "yellow": "#E5C07B"
        },
        {
            "background": "#FAFAFA",
            "black": "#383A42",
            "blue": "#0184BC",
            "brightBlack": "#4F525D",
            "brightBlue": "#61AFEF",
            "brightCyan": "#56B5C1",
            "brightGreen": "#98C379",
            "brightPurple": "#C577DD",
            "brightRed": "#DF6C75",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#E4C07A",
            "cursorColor": "#4F525D",
            "cyan": "#0997B3",
            "foreground": "#383A42",
            "green": "#50A14F",
            "name": "One Half Light",
            "purple": "#A626A4",
            "red": "#E45649",
            "selectionBackground": "#FFFFFF",
            "white": "#FAFAFA",
            "yellow": "#C18301"
        },
        {
            "background": "#002B36",
            "black": "#002B36",
            "blue": "#268BD2",
            "brightBlack": "#073642",
            "brightBlue": "#839496",
            "brightCyan": "#93A1A1",
            "brightGreen": "#586E75",
            "brightPurple": "#6C71C4",
            "brightRed": "#CB4B16",
            "brightWhite": "#FDF6E3",
            "brightYellow": "#657B83",
            "cursorColor": "#FFFFFF",
            "cyan": "#2AA198",
            "foreground": "#839496",
            "green": "#859900",
            "name": "Solarized Dark",
            "purple": "#D33682",
            "red": "#DC322F",
            "selectionBackground": "#FFFFFF",
            "white": "#EEE8D5",
            "yellow": "#B58900"
        },
        {
            "background": "#FDF6E3",
            "black": "#002B36",
            "blue": "#268BD2",
            "brightBlack": "#073642",
            "brightBlue": "#839496",
            "brightCyan": "#93A1A1",
            "brightGreen": "#586E75",
            "brightPurple": "#6C71C4",
            "brightRed": "#CB4B16",
            "brightWhite": "#FDF6E3",
            "brightYellow": "#657B83",
            "cursorColor": "#002B36",
            "cyan": "#2AA198",
            "foreground": "#657B83",
            "green": "#859900",
            "name": "Solarized Light",
            "purple": "#D33682",
            "red": "#DC322F",
            "selectionBackground": "#FFFFFF",
            "white": "#EEE8D5",
            "yellow": "#B58900"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#FFFFFF",
            "cyan": "#06989A",
            "foreground": "#D3D7CF",
            "green": "#4E9A06",
            "name": "Tango Dark",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#FFFFFF",
            "black": "#000000",
            "blue": "#3465A4",
            "brightBlack": "#555753",
            "brightBlue": "#729FCF",
            "brightCyan": "#34E2E2",
            "brightGreen": "#8AE234",
            "brightPurple": "#AD7FA8",
            "brightRed": "#EF2929",
            "brightWhite": "#EEEEEC",
            "brightYellow": "#FCE94F",
            "cursorColor": "#000000",
            "cyan": "#06989A",
            "foreground": "#555753",
            "green": "#4E9A06",
            "name": "Tango Light",
            "purple": "#75507B",
            "red": "#CC0000",
            "selectionBackground": "#FFFFFF",
            "white": "#D3D7CF",
            "yellow": "#C4A000"
        },
        {
            "background": "#000000",
            "black": "#000000",
            "blue": "#000080",
            "brightBlack": "#808080",
            "brightBlue": "#0000FF",
            "brightCyan": "#00FFFF",
            "brightGreen": "#00FF00",
            "brightPurple": "#FF00FF",
            "brightRed": "#FF0000",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#FFFF00",
            "cursorColor": "#FFFFFF",
            "cyan": "#008080",
            "foreground": "#C0C0C0",
            "green": "#008000",
            "name": "Vintage",
            "purple": "#800080",
            "red": "#800000",
            "selectionBackground": "#FFFFFF",
            "white": "#C0C0C0",
            "yellow": "#808000"
        }
    ]
}

Fixed

-p "Windows Powershell 7"
SHOULD HAVE BEEN
-p "Windows PowerShell 7"

答案1

得分: 1

你可能有一个以上名为"Windows Powershell"的配置文件。

要检查这一点,以下是获取涉及的配置文件列表的方法:

$myJSON = Get-Content "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\settings.json" -Raw | ConvertFrom-Json
$myJSON.profiles.list |  Where name -match "Windows Powershell"

在我的系统上,这只会给出一个配置文件:

colorScheme : Campbell Powershell
commandline : %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
guid        : {61c54bbd-c2c6-5271-96e7-009a87ff44bf}
hidden      : False
name        : Windows PowerShell

我认为(猜测)多个配置文件可能是导致你的问题的原因?

英文:

You might have more than one profile named "Windows Powershell".

To check that, here's how to get a list of the profiles involed:

$myJSON = Get-Content $myJSON = Get-Content "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\settings.json" -Raw | ConvertFrom-Json
$myJSON.profiles.list |  Where name -match "Windows Powershell"

On my system this only gives one profile:

colorScheme : Campbell Powershell
commandline : %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
guid        : {61c54bbd-c2c6-5271-96e7-009a87ff44bf}
hidden      : False
name        : Windows PowerShell

I think (guess) multiple profiles might be the cause of your problem ?

答案2

得分: 1

  • 对于 wt.exeWindows 终端CLI 需要识别一个 -p 参数(配置文件名称),必须与已定义配置文件的名称完全匹配,区分大小写1

    • 如果没有确切的匹配,Windows 终端将悄悄回退到默认配置文件(无论其名称是什么)。

    • 您也可以将配置文件的 GUID(您可以从 settings.json 文件中获取)传递给 -p(相同的回退逻辑适用)。

  • 因为您的 -p 参数与实际配置文件名称的大小写不匹配 - p "Windows Powershell 7"(注意 Powershell 中的小写 s)与 -p "Windows PowerShell 7" - 所以使用了您的默认配置文件。

    • 顺便提一下:不存在名为 Windows PowerShell 7:有 Windows PowerShell,这是传统版本,最新和最后一个版本是 5.1,还有 PowerShell (Core)(可能前缀是 Microsoft,但不是 Windows),这是现代、跨平台版本,当前版本为 v7.x(第一个版本是 v6.0)。

修复大小写不匹配的问题解决了您的问题。

1 不幸的是,也可以(不小心)创建多个具有完全相同名称但具有不同 GUID 的配置文件,在这种情况下,第一个定义的配置文件将生效(根据在设置界面显示的顺序)。相比之下,重复的配置文件 GUID(在使用设置界面时自动创建和分配)会被检测到并导致错误消息。

英文:

To provide the solution in the form of an answer:

  • For wt.exe, Windows Terminal's CLI to recognize a -p argument (profile name) if must match the name of a defined profile in full, case-exactly;<sup>1</sup>

    • If there is no exact match, Windows Terminal quietly falls back to the default profile (whatever its name is).

    • You may alternatively pass a profile's GUID (which you can glean from the settings.json file) to -p (the same fallback logic applies).

  • Because your -p argument differed in case from the actual profile name - p &quot;Windows Powershell 7&quot; (note the lowercase s in Powershell) vs. -p &quot;Windows PowerShell 7&quot; - your default profile was used instead.

    • As an aside: There is no such thing as Windows PowerShell 7: there's Windows PowerShell, the legacy edition whose latest and last version is 5.1, and there is PowerShell (Core) (possibly prefixed with Microsoft, but NOT Windows), the modern, cross-platform edition that is currently at v7.x (and whose first version was v6.0).

Fixing the case mismatch solved your problem.


<sup>1 It is (unfortunately) also possible to (accidentally) create multiple profiles with the exact same name (but different GUIDs), in which case the first one defined is the effective one (based on the order shown in the Settings GUI).
By contrast, duplicate profile GUIDs (which are automatically created and assigned when you use the Settings GUI) are detected and result in an error message.
</sup>

huangapple
  • 本文由 发表于 2023年4月10日 20:28:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977132.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定