Windows Terminal 使用

前言

Windows 终端是一个面向命令行工具和 shell(如命令提示符、PowerShell 和适用于 Linux 的 Windows 子系统 (WSL))用户的新式终端应用程序。 它的主要功能包括多个选项卡、窗格、Unicode 和 UTF-8 字符支持、GPU 加速文本呈现引擎,还可以用于创建你自己的主题并自定义文本、颜色、背景和快捷键绑定。

1. 安装

从 windows store中安装,搜索terminal 有两个,一个microsoft terminal一个windows terminal preview , 选择后者。
如果你无法访问 Microsoft Store,GitHub 发布页上发布有内部版本。 如果从 GitHub 安装,终端将不会自动更新为新版本。

2. 配置参考

可参考我的配置:

// This file was initially generated by Windows Terminal Preview 1.2.2022.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.

// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
  "$schema": "https://aka.ms/terminal-profiles-schema",

  "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

  // You can add more global application settings here.
  // To learn more about global settings, visit https://aka.ms/terminal-global-settings

  // If enabled, selections are automatically copied to your clipboard.
  "copyOnSelect": false,

  // If enabled, formatted data is also copied to your clipboard
  "copyFormatting": false,
  // A profile specifies a command to execute paired with information about how it should look and feel.
  // Each one of them will appear in the 'New Tab' dropdown,
  //   and can be invoked from the commandline with `wt.exe -p xxx`
  // To learn more about profiles, visit https://aka.ms/terminal-profile-settings
  "profiles": {
    "defaults": {
      // Put settings here that you want to apply to all profiles.
      "fontFace": "Cascadia Code",
      "fontSize": 10,
      "useAcrylic": true, //使用背景透明
      "acrylicOpacity": 0.8, //背景透明度
      "launchMode": "default", //启动大小 default , maximized , fullscreen
      "initialPosition": "800,#" //启动位置

    },
    "list": [
      {
        // Make changes here to the cmd.exe profile.
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "name": "命令提示符",
        "commandline": "cmd.exe",
        "hidden": false,
        "startingDirectory": null //默认值:"%USERPROFILE%",通过地址栏启动,输入 wt 即可打开Windows terminal (类似cmd)
      },
      {
        // Make changes here to the powershell.exe profile.
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "name": "Windows PowerShell",
        "commandline": "powershell.exe",
        "startingDirectory": null,
        "fontFace": "Cascadia Code PL",
        "hidden": false
      },
      {
        "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
        "hidden": true,
        "name": "Azure Cloud Shell",
        "source": "Windows.Terminal.Azure"
      },
      {
        "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b7}",
        "hidden": false,
        "name": "git bash",
        "icon": "D:\\Program Files\\Git\\favicon.ico",
        "commandline": "D:\\Program Files\\Git\\bin\\bash.exe"
      }
    ]
  },

  // Add custom color schemes to this array.
  // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
  "schemes": [],

  // Add custom keybindings to this array.
  // To unbind a key combination from your defaults.json, set the command to "unbound".
  // To learn more about keybindings, visit https://aka.ms/terminal-keybindings
  "keybindings": [
    // Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
    // These two lines additionally bind them to Ctrl+C and Ctrl+V.
    // To learn more about selection, visit https://aka.ms/terminal-selection
    {
      "command": {
        "action": "copy",
        "singleLine": false
      },
      "keys": "ctrl+c"
    },
    {
      "command": "paste",
      "keys": "ctrl+v"
    },

    // Press Ctrl+Shift+F to open the search box
    {
      "command": "find",
      "keys": "ctrl+shift+f"
    },

    // Press Alt+Shift+D to open a new pane.
    // - "split": "auto" makes this pane open in the direction that provides the most surface area.
    // - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
    // To learn more about panes, visit https://aka.ms/terminal-panes
    {
      "command": {
        "action": "splitPane",
        "split": "auto",
        "splitMode": "duplicate"
      },
      "keys": "alt+shift+d"
    }
  ]
}

效果图:


windows terminal

3. 添加git-bash 命令

在list中添加一个对象

 {
        "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b7}",
        "hidden": false,
        "name": "git bash",
        "icon": "D:\\Program Files\\Git\\favicon.ico",
        "commandline": "D:\\Program Files\\Git\\bin\\bash.exe"
}

其中guid可用工具生成, icon从官网下载(打开git-bash官网后,在控制台网络中可找到favicon.ico),放到适当位置,引用其位置即可。
commandline填写已安装的git下的bash.exe路径

4. 在powershell中使用git并带有命令行自动补全和漂亮的文本[可选]

[可选内容,喜欢折腾的用户随意]
参考:https://docs.microsoft.com/zh-cn/windows/terminal/tutorials/powerline-setup

  • 下载字体并安装:Cascadia Mono PL , 字体下载:CascadiaPL.ttf, 下载后直接双击字体即可安装。

  • 使用 PowerShell,安装 Posh-Git 和 Oh-My-Posh:

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

注意此处安装可能会失败,需要kexuejishu上网

  • 使用powershell 启动自动加载配置文件
echo $profile
Test-Path $profile
New-Item -Path $profile -Type File –Force

使用echo $profile检查.ps1文件是否存在,Test-Path $profile进一步测试是否存在,若不存在则用命令新建一个New-Item -Path $profile -Type File –Force

使用文本编辑器打开该 PowerShell 配置文件,该脚本在每次启动 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 git

  • 注意: 如果启动powershell时报错如下:
. : 无法加载文件 C:\Users\wweim\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,因为在此系统上禁止运行脚
本。有关详细信息,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\wweim\Documents\WindowsPowerShell\Microsoft.PowerShell_pr ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

则可根据https:/go.microsoft.com/fwlink/?LinkID=135170中的提示进行设置, 简单的方式可这样操作:
使用管理员权限打开powershell

Get-ExecutionPolicy
# 如果是Restricted, 则代表不能使用本地加载ps1
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# 设置本地用户执行策略为 RemoteSigned

完成, 重新打开terminal后进入powershell可发现已经可以加载ps1文件

5. 将本地cmd命令默认使用windows terminal打开

快捷键win+r后在打开的运行窗口输入cmd打开cmd窗口后在窗口头部右键选择属性打开属性对话框,然后选择终端,在默认终端应用程序中选择Windows Terminal即可,下次打开cmd时自动使用Windows Terminal终端打开

cmd选择Windows Terminal为默认终端

或者在打开的Windows Terminal终端中选择设置
Windows Terminal终端选择

设置-启动-默认终端应用程序

6. Windows Terminal启动快捷方式

方法1: win+s中输入wt即可启动Windows Terminal
方法2: win+r中输入wt即可启动Windows Terminal
方法3: 在文件夹路径上输入wt,此命令根目录为默认目录
方法4: (推荐)在文件夹路径上输入'cmd',此时命令根目录为当前目录
方法5: (推荐)大多数编辑器(如:vs,vscode,webstorm,idea等等)都自带终端,打开终端后直接输入start cmd也可打开终端, 而且终端根目录也是当前自带终端的根目录. 方便执行带有当前路径的命令.

总结

本文从安装到设置,再到默认切换终端,最后快捷的启动方式,简单的带你进入了Windows Terminal的世界, 从此一款高效、美观、现代的命令行工具伴随着我们的日常开发😊

参考:windows terminal官方文档

本文作者:wwmin
微信公众号: DotNet技术说
本文链接:https://www.jianshu.com/p/faeb78aed400
版权声明:转载请注明出处!
声援博主:如果您觉得文章对您有帮助,关注点赞, 您的鼓励是博主的最大动力!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 162,306评论 4 370
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 68,657评论 2 307
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 111,928评论 0 254
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,688评论 0 220
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 53,105评论 3 295
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 41,024评论 1 225
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,159评论 2 318
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,937评论 0 212
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,689评论 1 250
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,851评论 2 254
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,325评论 1 265
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,651评论 3 263
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,364评论 3 244
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,192评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,985评论 0 201
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 36,154评论 2 285
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,955评论 2 279

推荐阅读更多精彩内容