美文网首页
Windows Terminal 使用教程

Windows Terminal 使用教程

作者: DimonHo | 来源:发表于2020-08-24 01:14 被阅读0次

    安装

    在win10的应用商店中搜索windos terminal下载安装即可。


    美化

    1. 设置 Powerline

    Powerline 提供自定义的命令提示符体验,提供 Git 状态颜色编码和提示符


    image.png
    • 必备条件:安装 Powerline 字体

    Powerline 使用字形来设置提示符样式。 如果你的字体不包含 Powerline 字形,则在整个提示符中,你可能会看到若干 Unicode 替换字符“&#x25AF”。 尽管 Cascadia Mono 不包括 Powerline 字形,但你可以安装 Cascadia Code PL 或 Cascadia Mono PL,这两者包含 Powerline 字形。 可以从 Cascadia Code GitHub 发布页安装这些字体。

    使用 PowerShell,执行下面的命令分别安装 Posh-Git 和 Oh-My-Posh:

    Install-Module posh-git -Scope CurrentUser
    Install-Module oh-my-posh -Scope CurrentUser
    

    2. 自定义 PowerShell 提示符

    使用powershell执行下面的命令,新建或打开powershell的配置脚本

    notepad $PROFILE
    

    该脚本在每次启动 PowerShell 时运行。 详细了解 PowerShell 配置文件

    在 PowerShell 配置脚本中,将以下内容添加到文件的末尾:

    Import-Module posh-git
    Import-Module oh-my-posh
    Set-Theme Paradox
    

    现在,每个新实例启动时都会导入 Posh-Git 和 Oh-My-Posh,然后从 Oh-My-Posh 设置 Paradox 主题。 Oh-My-Posh 附带了若干内置主题

    上面的脚本执行可能会报错,如果报错的话,在powershell中执行下面的命令即可解决。参考:https://www.cnblogs.com/wswind/p/10911286.html

    Set-ExecutionPolicy Unrestricted
    

    3. 在设置中将 Cascadia Code PL 设置为 fontFace

    若要设置 Cascadia Code PL 以便与 PowerLine 一起使用(在系统中下载、解压缩和安装之后),需要通过从“Windows Terminal”下拉菜单中选择“设置”来打开 settings.json 文件中的配置文件设置

    settings.json 文件打开后,找到 Windows PowerShell 配置文件,并添加 "fontFace": "Cascadia Code PL",将 Cascadia Code PL 指定为字体。 这样就会显示很好看的 Cascadia Code Powerline 字形。

    Windows PowerShell 配置文件 settings.json 文件现在应如下所示:

    {
        // Make changes here to the powershell.exe profile.
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "name": "Windows PowerShell",
        "commandline": "powershell.exe",
        "fontFace": "Cascadia Code PL",
        "hidden": false
    },
    

    易用性改造

    1. 解决中文乱码问题

    在powershell中执行如下命令,打开powershell的配置脚本文件

    notepad.exe $PROFILE
    

    在脚本末尾加入如下代码即可:

    $env:LESSCHARSET='utf-8'
    

    2. 添加terminal到右键菜单

    准备一个自己喜欢的图标文件
    新建一个windowsterminal.reg脚本文件

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\shell\OpenCmdHere]
    @="在此处打开命令提示符"
    "Icon"="C:\\win10\\icon\\terminal.png"
    
    [HKEY_CLASSES_ROOT\Directory\shell\OpenCmdHere\command]
    @="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere]
    @="在此处打开命令窗口"
    "Icon"="C:\\win10\\icon\\terminal.png"
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\OpenCmdHere\command]
    @="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"
    
    [HKEY_CLASSES_ROOT\Drive\shell\OpenCmdHere]
    @="在此处打开命令窗口"
    "Icon"="C:\\win10\\icon\\terminal.png"
    
    [HKEY_CLASSES_ROOT\Drive\shell\OpenCmdHere\command]
    @="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"
    
    [HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenCmdHere]
    @="在此处打开命令窗口"
    "Icon"="C:\\win10\\icon\\terminal.png"
    
    [HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenCmdHere\command]
    @="C:\\Users\\Administrator\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"
    

    保存后双击运行一下即可。

    不过虽然能打开终端,但是路径并不是当前路径,需要在修改windows terminal配置:
    打开 Windows Terminal --> 设置,给 profiles.defaults 加上这么一句:

    "startingDirectory": null
    

    另一种添加到右键菜单的方法
    新建一个windowsterminal.reg脚本文件

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
    @="open windows terminal"
    "Icon"="C:\\Users\\vampi\\Pictures\\icon\\terminal.ico"
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
    @="wt.exe -d %V"
    
    [HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\runas]
    @="open windows terminal 管理员"
    "Icon"="C:\\Users\\vampi\\Pictures\\icon\\terminal.ico"
    
    [HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell\runas\command]
    @="cmd.exe /k \"wt.exe -d %V&&exit\""
    

    双击运行即可。

    相关文章

      网友评论

          本文标题:Windows Terminal 使用教程

          本文链接:https://www.haomeiwen.com/subject/tvtgjktx.html