Windows Terminal 捣鼓

安装: Win10 商店.

添加 Git Bash 支持

打开设置, 在 profiles -> list 添加以下必须项:

{
    "guid": "{c169f907-832c-4aa4-9ab3-84a4658b4b93}",
    "name" : "Git Bash",
    "commandline" : "C:\\Program Files\\Git\\bin\\bash.exe -i -l",
    "icon" : "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico"
}

其他的配置看自己喜好就行, 我都定义在 defaults 里了, 所以这里只有四项.

其中,

guid 其实随便填一个与其他 shell 不同的序列号即可, 这里我是用 Visual Studio 生成了一个.

commandline 定位到 Git Bash 安装路径下的 bin 文件夹. 注意要带上 -i -l 的参数. 参数的作用: 如果不加, 则不会加载 Git Bash 的配置, 会打开一个没有自定义过的 Bash. 事实上, Git 自带的 Bash Terminal 启动时带的参数就是这个: 在这里插入图片描述

个人配置喜好

在打开设置时按住 Alt, 会打开 defaults.json, 里面有所有设置的默认值, 可以拿来作参考.

以下是我的 settings.jsonprofiles 部分:

"profiles":
{
    "defaults":
    {
        "startingDirectory": ".",
        "closeOnExit": "graceful",
        "historySize": 9001,
        "snapOnInput": true,
        "colorScheme": "One Half Dark",
        "fontFace": "Cascadia Mono",
        "fontSize": 12,
        "antialiasingMode": "grayscale",
        "useAcrylic": true,
        "acrylicOpacity" : 0.9,
        "padding": "8, 8, 8, 8",
        "cursorShape": "bar"
    },
    "list":
    [
        {
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "name": "Windows PowerShell",
            "commandline": "powershell.exe"
        },
        {
            "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
            "name": "命令提示符",
            "commandline": "cmd.exe"
        },
        {
            "guid": "{c169f907-832c-4aa4-9ab3-84a4658b4b93}",
            "name" : "Git Bash",
            "commandline" : "C:\\Program Files\\Git\\bin\\bash.exe -i -l",
            "icon" : "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico"
        },
        {
            "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
            "hidden": false,
            "name": "Azure Cloud Shell",
            "source": "Windows.Terminal.Azure"
        }
    ]
},

Windows Terminal 添加到右键菜单

要求效果类似 Git Bash Here, 在此处打开 Powershell 窗口(s), 通过 Code 打开 这种, 在文件夹空白处右键出现菜单:

在这里插入图片描述

原理就仿照上面那几位, 创建类似效果的注册表. 上面几个软件的菜单都能在注册表编辑器的如下位置找到:

计算机\HKEY_CLASSES_ROOT\Directory\Background\shell

新建一个 .reg 文件, 写入如下内容:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows Terminal here"
"Icon"="<path-to-your-ico>"
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="C:\\Users\\<user>\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

其中,

  • 第 5 行 “Icon” 是图标的路径, 图标随意, 放的路径也随意. 如果不需要图标就删掉这行.

    如果要 Windows Terminal 官方图标, 在他们的 Github 上有: https://github.com/microsoft/terminal/blob/master/res/terminal.ico.

    当然, 上面这个链接只是 Github 上该文件的页面, 转换成源文件链接就是 https://raw.githubusercontent.com/microsoft/terminal/master/res/terminal.ico, 点击即下.

  • 第 6 行 “Extended” 代表需要按住 Shift 才能显示, 就像 Powershell 一样, 删掉该行则不需要按 Shift 也能显示.

  • 第 9 行是 Windows Terminal 的绝对路径 (记得改 <user>), 必须是完全的绝对路径, 不可以是

    %USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe
    

    %LOCALAPPDATA%\\Microsoft\\WindowsApps\\wt.exe
    

    原因不明, 总之如果不填写完整的绝对路径, 它就报错.

    另外有人的 Windows Terminal 名字是 wtd.exe 而不是 wt.exe, 先去目录确认一下.

我自己用的 right-click menu.reg:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows Terminal here"
"Icon"="%LOCALAPPDATA%\\WindowsTerminal\\terminal.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="C:\\Users\\xie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

注册后右键的效果上面已经展示了.

然后还有问题, 右键打开后 Windows Terminal 路径总是为 C:\Users\<user>. 解决方法有两种:

  1. Windows Terminal 默认启动路径一直是 user profile. 所以打开其 settings.json"startingDirectory": "%USERPROFILE%" 改为 "startingDirectory": ".".

    这个方法比较推荐, 但也有缺点: 改了 startingDirectory 之后, 从开始菜单直接打开 Windows Terminal 会显示路径为 C:\WINDOWS\system32.

  2. 不改 startingDirectory 其实也可以. wt.exe 有个参数 -d 用于设定目录. 所以可以把 .reg 最后一行的 command 改为:

    @="C:\\Users\\xie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -d ."
    

    于是不用设置 startingDirectory, 打开也是当前目录. 但缺点也很明显, 它只限定打开的第一个 terminal 的目录, 如果你按加号新建一个 terminal, 目录就又变成 C:\Users\<user> 了.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值