Windows Terminal 使用

前言

Windows 終端是一個(gè)面向命令行工具和 shell(如命令提示符友扰、PowerShell 和適用于 Linux 的 Windows 子系統(tǒng) (WSL))用戶(hù)的新式終端應(yīng)用程序仗阅。 它的主要功能包括多個(gè)選項(xiàng)卡蛉谜、窗格签餐、Unicode 和 UTF-8 字符支持哗讥、GPU 加速文本呈現(xiàn)引擎辙芍,還可以用于創(chuàng)建你自己的主題并自定義文本铆帽、顏色咆耿、背景和快捷鍵綁定。

1. 安裝

從 windows store中安裝爹橱,搜索terminal 有兩個(gè)萨螺,一個(gè)microsoft terminal一個(gè)windows terminal preview , 選擇后者。
如果你無(wú)法訪問(wèn) Microsoft Store,GitHub 發(fā)布頁(yè)上發(fā)布有內(nèi)部版本慰技。 如果從 GitHub 安裝椭盏,終端將不會(huì)自動(dòng)更新為新版本。

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", //啟動(dòng)大小 default , maximized , fullscreen
      "initialPosition": "800,#" //啟動(dòng)位置

    },
    "list": [
      {
        // Make changes here to the cmd.exe profile.
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "name": "命令提示符",
        "commandline": "cmd.exe",
        "hidden": false,
        "startingDirectory": null //默認(rèn)值:"%USERPROFILE%"惹盼,通過(guò)地址欄啟動(dòng)庸汗,輸入 wt 即可打開(kāi)Windows terminal (類(lèi)似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中添加一個(gè)對(duì)象

 {
        "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"
}

其中g(shù)uid可用工具生成, icon從官網(wǎng)下載(打開(kāi)git-bash官網(wǎng)后手报,在控制臺(tái)網(wǎng)絡(luò)中可找到favicon.ico),放到適當(dāng)位置蚯舱,引用其位置即可。
commandline填寫(xiě)已安裝的git下的bash.exe路徑

4. 在powershell中使用git并帶有命令行自動(dòng)補(bǔ)全和漂亮的文本[可選]

[可選內(nèi)容,喜歡折騰的用戶(hù)隨意]
參考: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

注意此處安裝可能會(huì)失敗兄裂,需要kexuejishu上網(wǎng)

  • 使用powershell 啟動(dòng)自動(dòng)加載配置文件
echo $profile
Test-Path $profile
New-Item -Path $profile -Type File –Force

使用echo $profile檢查.ps1文件是否存在,Test-Path $profile進(jìn)一步測(cè)試是否存在阳藻,若不存在則用命令新建一個(gè)New-Item -Path $profile -Type File –Force

使用文本編輯器打開(kāi)該 PowerShell 配置文件,該腳本在每次啟動(dòng) PowerShell 時(shí)運(yùn)行晰奖。 詳細(xì)了解 PowerShell 配置文件
在 PowerShell 配置文件中腥泥,將以下內(nèi)容添加到文件的末尾:

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

現(xiàn)在匾南,每個(gè)新實(shí)例啟動(dòng)時(shí)都會(huì)導(dǎo)入 Posh-Git 和 Oh-My-Posh,然后從 Oh-My-Posh 設(shè)置 Paradox 主題蛔外。 Oh-My-Posh 附帶了若干內(nèi)置主題蛆楞。
效果如下:

帶有命令補(bǔ)全和漂亮窗體的powershell git

  • 注意: 如果啟動(dòng)powershell時(shí)報(bào)錯(cuò)如下:
. : 無(wú)法加載文件 C:\Users\wweim\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,因?yàn)樵诖讼到y(tǒng)上禁止運(yùn)行腳
本夹厌。有關(guān)詳細(xì)信息豹爹,請(qǐng)參閱 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

則可根據(jù)https:/go.microsoft.com/fwlink/?LinkID=135170中的提示進(jìn)行設(shè)置, 簡(jiǎn)單的方式可這樣操作:
使用管理員權(quán)限打開(kāi)powershell

Get-ExecutionPolicy
# 如果是Restricted, 則代表不能使用本地加載ps1
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# 設(shè)置本地用戶(hù)執(zhí)行策略為 RemoteSigned

完成, 重新打開(kāi)terminal后進(jìn)入powershell可發(fā)現(xiàn)已經(jīng)可以加載ps1文件

5. 將本地cmd命令默認(rèn)使用windows terminal打開(kāi)

快捷鍵win+r后在打開(kāi)的運(yùn)行窗口輸入cmd打開(kāi)cmd窗口后在窗口頭部右鍵選擇屬性打開(kāi)屬性對(duì)話框,然后選擇終端,在默認(rèn)終端應(yīng)用程序中選擇Windows Terminal即可,下次打開(kāi)cmd時(shí)自動(dòng)使用Windows Terminal終端打開(kāi)

cmd選擇Windows Terminal為默認(rèn)終端

或者在打開(kāi)的Windows Terminal終端中選擇設(shè)置
Windows Terminal終端選擇

設(shè)置-啟動(dòng)-默認(rèn)終端應(yīng)用程序

6. Windows Terminal啟動(dòng)快捷方式

方法1: win+s中輸入wt即可啟動(dòng)Windows Terminal
方法2: win+r中輸入wt即可啟動(dòng)Windows Terminal
方法3: 在文件夾路徑上輸入wt,此命令根目錄為默認(rèn)目錄
方法4: (推薦)在文件夾路徑上輸入'cmd',此時(shí)命令根目錄為當(dāng)前目錄
方法5: (推薦)大多數(shù)編輯器(如:vs,vscode,webstorm,idea等等)都自帶終端,打開(kāi)終端后直接輸入start cmd也可打開(kāi)終端, 而且終端根目錄也是當(dāng)前自帶終端的根目錄. 方便執(zhí)行帶有當(dāng)前路徑的命令.

總結(jié)

本文從安裝到設(shè)置,再到默認(rèn)切換終端,最后快捷的啟動(dòng)方式,簡(jiǎn)單的帶你進(jìn)入了Windows Terminal的世界, 從此一款高效臂聋、美觀、現(xiàn)代的命令行工具伴隨著我們的日常開(kāi)發(fā)??

參考:windows terminal官方文檔

本文作者:wwmin
微信公眾號(hào): DotNet技術(shù)說(shuō)
本文鏈接:http://www.reibang.com/p/faeb78aed400
版權(quán)聲明:轉(zhuǎn)載請(qǐng)注明出處或南!
聲援博主:如果您覺(jué)得文章對(duì)您有幫助逻住,關(guān)注點(diǎn)贊, 您的鼓勵(lì)是博主的最大動(dòng)力!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末迎献,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子腻贰,更是在濱河造成了極大的恐慌吁恍,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,682評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異冀瓦,居然都是意外死亡伴奥,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)翼闽,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)拾徙,“玉大人,你說(shuō)我怎么就攤上這事感局∧岱龋” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 165,083評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵询微,是天一觀的道長(zhǎng)崖瞭。 經(jīng)常有香客問(wèn)我,道長(zhǎng)撑毛,這世上最難降的妖魔是什么书聚? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,763評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮藻雌,結(jié)果婚禮上雌续,老公的妹妹穿的比我還像新娘。我一直安慰自己胯杭,他們只是感情好驯杜,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,785評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著歉摧,像睡著了一般艇肴。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上叁温,一...
    開(kāi)封第一講書(shū)人閱讀 51,624評(píng)論 1 305
  • 那天再悼,我揣著相機(jī)與錄音,去河邊找鬼膝但。 笑死冲九,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的跟束。 我是一名探鬼主播莺奸,決...
    沈念sama閱讀 40,358評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼冀宴!你這毒婦竟也來(lái)了灭贷?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,261評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤略贮,失蹤者是張志新(化名)和其女友劉穎甚疟,沒(méi)想到半個(gè)月后仗岖,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,722評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡览妖,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,900評(píng)論 3 336
  • 正文 我和宋清朗相戀三年轧拄,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片讽膏。...
    茶點(diǎn)故事閱讀 40,030評(píng)論 1 350
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡檩电,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出府树,到底是詐尸還是另有隱情俐末,我是刑警寧澤,帶...
    沈念sama閱讀 35,737評(píng)論 5 346
  • 正文 年R本政府宣布挺尾,位于F島的核電站鹅搪,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏遭铺。R本人自食惡果不足惜丽柿,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,360評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望魂挂。 院中可真熱鬧甫题,春花似錦、人聲如沸涂召。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,941評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)果正。三九已至炎码,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間秋泳,已是汗流浹背潦闲。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,057評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留迫皱,地道東北人歉闰。 一個(gè)月前我還...
    沈念sama閱讀 48,237評(píng)論 3 371
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像卓起,于是被迫代替她去往敵國(guó)和親和敬。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,976評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容