Windows Terminal使用詳解
title: Windows Terminal使用詳解?
author: Mir小熊?
date: 2022年07月25日 weather: ?? ???+35°C ???↑11km/h?
summary:?
categories:
?裝機
tags:
?Windows Terminal
?zsh
介紹
在Build 2019大會上,微軟公布了新的
Windows Terminal
命令行終端工具,這是一個現(xiàn)代化的快速終端應(yīng)用程序,適用于命令行工具和shell,包括命令提示符、PowerShell和WSL
。Windows Terminal應(yīng)用程序帶有幾個新功能,如多選項卡支持,GPU加速DirectWrite/DirectX文本呈現(xiàn)引擎,支持許多設(shè)置和配置選項,允許用戶個性化終端的外觀等等。因為早期預(yù)覽沒有完整功能,自定義選項只能通過編輯JSON文件,慶幸的是Microsoft提供了有關(guān)如何在JSON文件中配置設(shè)置和鍵綁定的一些說明,您甚至可以更改背景圖像。
1. 下載安裝
安裝方式一、編譯安裝
Windows Terminal是開源軟件,大家可以到GitHub上下載后編譯安裝,這幾年巨硬確實開放了好多,不比水果搞封閉生態(tài)。
Windows Terminal GitHub[1]
也有博客介紹如何安裝,這里就不重復造輪子了
win10 terminal 折騰![2]
安裝方式二、Microstore Store商店安裝
這是本文介紹重點。原本我也想自己編譯安裝,只是一來工作太忙沒空折騰環(huán)境,二來微軟也表示六月中旬會在商店發(fā)布預(yù)覽版。今天想起這事兒來,上去商店搜索一下果然發(fā)布了預(yù)覽版。
安裝步驟
1.
打開應(yīng)用商店,在搜索框輸入Windows Terminal

1.點擊進行搜索就會跳轉(zhuǎn)到Windows Terminal 頁面,然后點擊Get進行安裝

1.在這里我們可能會遇到問題,系統(tǒng)版本過低 Windows Terminal要求windows 10 version 18362.0
具體要求在Windows Terminal的System Requirements頁面有展示,翻到系統(tǒng)要求頁面然后點擊升級(Update)即可

1.點擊升級后會調(diào)到微軟官網(wǎng)的升級頁面,點擊下載升級工具 https://www.microsoft.com/en-us/software-download/windows10

1.升級工具下載完成后雙擊

1.開始升級,接下來就是漫長的等待

1.升級完畢

重啟后就是最新的windows10啦
1.重新進入商店下搜索安裝Windows Terminal

1.安裝后在開始菜單中打開

2. 配置
2.1 配置Git Bash
^960d84
方式一、通過配置文件配置
打開Windows Terminal 的JSON配置文件
1.通過快捷鍵Ctrl + Shift + ,
打開2.通過如下步驟打開


添加如下配置:

// 默認啟動為Git Bash
"defaultProfile": "{a2f405de-0bc6-11ed-861d-0242ac120002}",
"profiles":
? ?{
? ? ? ?"defaults":
? ? ? ?{
? ? ? ? ? ?"bellStyle": "taskbar",
? ? ? ? ? ?"closeOnExit": "graceful",
? ? ? ? ? ?"font":
? ? ? ? ? ?{
? ? ? ? ? ? ? ?"face": "Hack NF"
? ? ? ? ? ?},
? ? ? ? ? ?"opacity": 90,
? ? ? ? ? ?// 啟動目錄
? ? ? ? ? ?"startingDirectory": "%USERPROFILE%\\Desktop",
? ? ? ? ? ?// 輸入的時候,窗口自動滾到最下方
? ? ? ? ? ?"snapOnInput" : true,
? ? ? ? ? ?// 關(guān)閉的時候退出
? ? ? ? ? ?"closeOnExit" : true
? ? ? ?},
? ? ? ?"list":
? ? ? ?[
? ? ? ? ? ?...
? ? ? ? ? ?{
? ? ? ? ? ? ? ?"commandline": "E:\\tools\\Git\\bin\\bash.exe --login -i",
? ? ? ? ? ? ? ?"guid": "{a2f405de-0bc6-11ed-861d-0242ac120002}",
? ? ? ? ? ? ? ?"hidden": false,
? ? ? ? ? ? ? ?"icon": "D:\\picture\\git-bash.png",
? ? ? ? ? ? ? ?"name": "Git Bash"
? ? ? ? ? ?},
? ? ? ? ? ?...
? ? ? ?]
? ?},
說明:
?guid
:唯一標識本命令行配置,可以使用?在線guid工具[1]隨機生成一個和list中其他配置不一樣的guid即可?name
:本命令行配置的名字,會顯示在菜單中?commandline
:表示怎么啟動一個命令行,這里填的是E:\\Git\\bin\\bash.exe --login -i
,需要找到你的Git的安裝目錄,將E:\\Git\\bin\\bash.exe
替換成你自己的路徑?icon
:顯示在菜單中的圖標,這里提供一個:

方式一、通過圖形界面配置
1.
打開Windows Terminal
設(shè)置界面

2.
新建配置文件

3.
新空配置文件

4.
配置

5.
設(shè)置?Git Bash
為默認啟動程序

2.2 配置透明度
1.
打開Windows Terminal
設(shè)置界面

2.
打開默認值的外觀設(shè)置

3.
設(shè)置透明度比例

2.3 配置配色方案
1.
打開Windows Terminal
設(shè)置界面

2.
打默認值->配色方案
配置默認的配色方案

3.
對于不通的終端也可可以不使用默認值,自定義使用配色方案


新建配色方案
方式一、通過配置文件新建配色方案
參考配置Git Bash[2]?打開配置文件 在
[]schemes
數(shù)組下添加一個對象:
推薦配色方案:
// 默認啟動為Git Bash
"defaultProfile": "{a2f405de-0bc6-11ed-861d-0242ac120002}",
"profiles":
? ? {
? ? ? ? "defaults":
? ? ? ? {
? ? ? ? ? ? "bellStyle": "taskbar",
? ? ? ? ? ? "closeOnExit": "graceful",
? ? ? ? ? ? "font":
? ? ? ? ? ? {
? ? ? ? ? ? ? ? "face": "Hack NF"
? ? ? ? ? ? },
? ? ? ? ? ? "opacity": 90,
? ? ? ? ? ? // 啟動目錄
? ? ? ? ? ? "startingDirectory": "%USERPROFILE%\\Desktop",
? ? ? ? ? ? // 輸入的時候,窗口自動滾到最下方
? ? ? ? ? ? "snapOnInput" : true,
? ? ? ? ? ? // 關(guān)閉的時候退出
? ? ? ? ? ? "closeOnExit" : true
? ? ? ? },
? ? ? ? "list":
? ? ? ? [
? ? ? ? ? ? ...
? ? ? ? ? ? {
? ? ? ? ? ? ? ? "commandline": "E:\\tools\\Git\\bin\\bash.exe --login -i",
? ? ? ? ? ? ? ? "guid": "{a2f405de-0bc6-11ed-861d-0242ac120002}",
? ? ? ? ? ? ? ? "hidden": false,
? ? ? ? ? ? ? ? "icon": "D:\\picture\\git-bash.png",
? ? ? ? ? ? ? ? "name": "Git Bash"
? ? ? ? ? ? },
? ? ? ? ? ? ...
? ? ? ? ]
? ? },
方式二、通過圖形界面新建配色方案
1.
打開Windows Terminal
設(shè)置界面

2.
配色方案->新增


配色網(wǎng)站
?Windows Terminal Themes[3]?iTerm2-Color-Schemes/windowsterminal at master · mbadolato/iTerm2-Color-Schemes[4]
2.4 安裝下載ZSH
在 Windows 環(huán)境下為 Git Bash 安裝 zsh (非WSL)
安裝zsh
進入MSYS2 Packages[1]點擊File
下載.zst
壓縮包,如圖所示:

使用Bandizip
或者7-Zip-zstd[2]解壓zsh-5.8-5-x86_64.pkg
,解壓后文件結(jié)構(gòu)如圖所示:
將對應(yīng)的目錄中的內(nèi)容移動到Git
的安裝目錄中

移動完成后,Git
的安裝目錄如下結(jié)構(gòu):

打開Git Bash
標簽頁輸入zsh
,出現(xiàn)下圖則代表安裝成功,否則檢查是否解壓至Git
根目錄下

出現(xiàn)上圖,則代表需要進行初始化配置(具體配置可自行百度),在終端輸入1
后如圖:

依次設(shè)置好Recommended.
項后,輸入0
退出(務(wù)必生成.zshrc
文件),之后在終端(Git Bash
標簽頁)輸入zsh
,出下圖即可。

執(zhí)行?
cd
?命令可以轉(zhuǎn)到根目錄【默認位置為:/c/Users/Administrator
】,在該目錄下可以看見生成的.zshrc
文件
2.5 安裝下載OH-MY-ZSH
進入官網(wǎng)[3],復制首頁命令進行安裝。
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
若出現(xiàn)curl: (6) Could not resolve host: raw.githubusercontent.com
報錯,則在hosts
下添加一下內(nèi)容,重試即可。
199.232.68.133 raw.githubusercontent.com
安裝完成后出現(xiàn)下圖內(nèi)容代表安裝成功(若出現(xiàn)ERROR
忽略即可)

配置?Oh My Zsh
?主題
Oh My Zsh
主題文件在~/.oh-my-zsh/themes
下,各個主題預(yù)覽可參見官方WiKi[4],默認主題為robbyrussell
。想更換主題在~/.zshrc
文件中新增/修改ZSH_THEME
字段的配置。
如果不想折騰,推薦使用如下主題:

安裝?powerlevel10k
?主題
可參考ZSH打造一款漂亮的終端[5]]
在安裝powerlevel10k
主題前需要安裝需要推薦的字體[6], 字體安裝完成后分別在Windows Terminal
與Git Bash
配置字體。
在Windows Terminal
中打開settings.json
,在_profiles → defaults_設(shè)置"fontFace": "MesloLGS NF"
。

在Git Bash
右鍵選項(Options
),點擊文本(Text
)配置字體。

配置好字體后,在終端輸入以下命令進行安裝:
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
安裝完成后在~/.zshrc
文件中設(shè)置ZSH_THEME="powerlevel10k/powerlevel10k"
,并在終端輸入以下命令更新.zshrc
配置文件:
source ~/.zshrc
之后會顯示下圖信息進行配置,輸入y
后根據(jù)個人喜好配置。若之后覺得配置不合適,可在終端輸入p10k configure
重新配置。

如果覺得終端顯示的文件路徑過長,只想顯示最后一個文件夾,可在~/.p10k.zsh
文件中將?POWERLEVEL9K_SHORTEN_STRATEGY
的參數(shù)改為?truncate_to_last
。
typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_last
配置默認啟動zsh
在{Git的安裝目錄位置}/etc/bash.bashrc
文件末尾追加以下內(nèi)容:
# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi
之后每次啟動/新建Git Bash
,都會是zsh
。
安裝zsh-autosuggestions
插件
zsh-autosuggestions
可以快速將歷史命令呈現(xiàn)出來,具體可參考官方說明[7]。
安裝
cd ~/.oh-my-zsh/custom/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
配置
在終端輸入以下命令,或直接用文本編輯器打開.zshrc
文件:
vi ~/.zshrc
添加以下內(nèi)容,表示新增zsh-autosuggestions
插件:
plugins=(git zsh-autosuggestions)

在終端輸入以下命令更新.zshrc
配置文件,或新建終端:
source ~/.zshrc
更改?zsh-autosuggestions
?提示顏色
在~/.zshrc
文件中新增/修改ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE
字段的配置,具體可參考官方文檔[8]。
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#9fc5e8"
References
[1]
?MSYS2 Packages:?https://link.zhihu.com/?target=https%3A//packages.msys2.org/package/zsh%3Frepo%3Dmsys%26variant%3Dx86_64[2]
?7-Zip-zstd:?https://link.zhihu.com/?target=https%3A//github.com/mcmilk/7-Zip-zstd/releases[3]
?官網(wǎng):?https://link.zhihu.com/?target=https%3A//ohmyz.sh/%23install[4]
?官方WiKi:?https://link.zhihu.com/?target=https%3A//github.com/ohmyzsh/ohmyzsh/wiki/Themes[5]
?ZSH打造一款漂亮的終端:?../../服務(wù)器/ZSH打造一款漂亮的終端.md[6]
?字體:?https://link.zhihu.com/?target=https%3A//github.com/romkatv/powerlevel10k%23meslo-nerd-font-patched-for-powerlevel10k[7]
?官方說明:?https://link.zhihu.com/?target=https%3A//github.com/zsh-users/zsh-autosuggestions[8]
?官方文檔:?https://link.zhihu.com/?target=https%3A//github.com/zsh-users/zsh-autosuggestions%23suggestion-highlight-style[9]
?一文搞定 Windows Terminal 設(shè)置與 zsh?安裝非WSL?- 知乎:?https://zhuanlan.zhihu.com/p/455925403[10]
?(31條消息) Windows10如何安裝windows terminal_二流小寶的博客-CSDN博客:?https://blog.csdn.net/SweetTool/article/details/94591100[11]
?Windows Terminal添加Git Bash支持_mob604756f692f5的技術(shù)博客_51CTO博客:?https://blog.51cto.com/u_15127602/3629778[12]
?(53 封私信 / 76 條消息) win10 terminal配色可以好看到什么程度?能分享你的profile.json嗎? - 知乎:?https://www.zhihu.com/question/330813656[13]
?Windows-Terminal 配置 OhMyPosh 來美化 GitBash | 偕臧:?https://ifmet.cn/posts/7bcfb552/[14]
?Windows 下的 Git Bash 配置,提升你的終端操作體驗 | Achuan-2:?https://achuan-2.github.io/posts/be43.html[15]
?zsh+on-my-zsh配置教程指南(程序員必備)【已備份】 - SegmentFault 思否:?https://segmentfault.com/a/1190000013612471[16]
?Windows Terminal 配色方案說明 - Yogile - 博客園:?https://www.cnblogs.com/Yogile/p/13290706.html