Windows Terminal + PowerShell Core 美化

最終效果

安裝 Windows Terminal

應用商店中搜索, 下載

下載 PowerShell Core

https://github.com/PowerShell/PowerShell/releases

字體

Sarasa[更紗黑體]

https://github.com/be5invis/Sarasa-Gothic

這裏是搬運地址:
https://download.csdn.net/download/MAIMIHO/12490128

安裝 Sarasa Term SC

Windows terminal Setting

打開 Windows terminal 設置, 替換如下, 注意裏面的路徑替換爲自己的

{
  "$schema": "https://aka.ms/terminal-profiles-schema",
  "defaultProfile": "{195e5e70-802f-4ae6-a4e6-57eff2b90258}",
  "copyOnSelect": false,
  "copyFormatting": false,
  "theme": "dark",
  "launchMode": "maximized",
  "snapToGridOnResize": false,
  "profiles": {
    "defaults": {
      "colorScheme": "Dracula",
      //背景透明度,
      "acrylicOpacity": 0.8,
      // 啓用毛玻璃,
      "useAcrylic": true,
      //背景圖片,
      "backgroundImage": "你的背景圖片路徑",
      //圖片透明度,
      "backgroundImageOpacity": 0.5,
      //填充模式,
      "backgroundImageStretchMode": "fill",
      //字體,
      "fontFace": "Sarasa Term SC",
      //文字大小,
      "fontSize": 14,
      //光標顏色,
      "cursorColor": "#FFFFFF",
      //光標形狀,
      "cursorShape": "bar",
      "startingDirectory": ".",
      "antialiasingMode": "cleartype"
    },
    "list": [
      {
        "guid": "{195e5e70-802f-4ae6-a4e6-57eff2b90258}",
        "name": "PowerShell Core",
        "icon": "C:\\Dev\\PowerShell\\assets\\Powershell_av_colors.ico",
        "commandline": "C:\\Dev\\PowerShell\\pwsh.exe -nologo",
        "hidden": false
      },
      {
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "name": "Windows PowerShell",
        "commandline": "powershell.exe",
        "hidden": false
      },
      {
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "name": "命令提示符",
        "commandline": "cmd.exe",
        "hidden": false
      },
      {
        "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
        "hidden": false,
        "name": "Azure Cloud Shell",
        "source": "Windows.Terminal.Azure"
      }
    ]
  },
  "schemes": [
    {
      "name": "Dracula",
      "background": "#272935",
      "black": "#21222C",
      "blue": "#BD93F9",
      "cyan": "#8BE9FD",
      "foreground": "#F8F8F2",
      "green": "#50FA7B",
      "purple": "#FF79C6",
      "red": "#FF5555",
      "white": "#F8F8F2",
      "yellow": "#FFB86C",
      "brightBlack": "#6272A4",
      "brightBlue": "#D6ACFF",
      "brightCyan": "#A4FFFF",
      "brightGreen": "#69FF94",
      "brightPurple": "#FF92DF",
      "brightRed": "#FF6E6E",
      "brightWhite": "#F8F8F2",
      "brightYellow": "#FFFFA5"
    }
  ],
  "keybindings": [
    {
      "command": {
        "action": "copy",
        "singleLine": false
      },
      "keys": "ctrl+c"
    },
    {
      "command": "paste",
      "keys": "ctrl+v"
    },
    {
      "command": "find",
      "keys": "ctrl+shift+f"
    },
    {
      "command": {
        "action": "splitPane",
        "split": "auto",
        "splitMode": "duplicate"
      },
      "keys": "alt+shift+d"
    }
  ]
}

權限設置

##允許執行腳本
set-executionpolicy remotesigned

安裝模塊

遇到提示統一選 Y

Install-Module -Name PSReadLine -AllowPrerelease -Force
Install-Module git-aliases -AllowClobber
Install-Module posh-git
Install-Module oh-my-posh
Install-Module DirColors

保存配置

打開配置文件

code $PROFILE (notpad $PROFILE) # VSCode or 記事本打開

輸入以下 -> 保存

Import-Module DirColors
Import-Module posh-git
Import-Module oh-my-posh
Import-Module git-aliases -DisableNameChecking
Set-Theme PowerLine

#-------------------------------  Set Hot-keys BEGIN  -------------------------------
# 設置 Tab 鍵補全
# Set-PSReadlineKeyHandler -Key Tab -Function Complete

# 設置 Tab 爲菜單補全和 Intellisense
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete

# 設置 Ctrl+d 爲退出 PowerShell
Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit

# 設置 Ctrl+z 爲撤銷
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo

# 設置向上鍵爲後向搜索歷史記錄
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward

# 設置向下鍵爲前向搜索歷史紀錄
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

# 一些PSReadline配置
$PSReadLineOptions = @{
    EditMode = "Windows"
    HistoryNoDuplicates = $true
    HistorySearchCursorMovesToEnd = $true
    ShowToolTips = $true
    Colors = @{
        # 提示文字顏色,原來的顏色太淺了,我這裏換了
        Prediction = '#888888'
    }
}
Set-PSReadLineOption @PSReadLineOptions

#-------------------------------  Set Hot-keys END    -------------------------------

加入右鍵菜單

win+r 輸入 regedit 計算機\HKEY_CLASSES_ROOT\Directory\Background\shell

shell 下新建 wt

wt 默認Open Windows Terminal here

wt 下 新建 字符串值 IconC:\Dev\PowerShell\assets\Powershell_av_colors.ico

wt 下 新建 commandC:\Users\[你的用戶名]\AppData\Local\Microsoft\WindowsApps\wt.exe


參考

https://github.com/dracula/windows-terminal

https://docs.microsoft.com/zh-cn/windows/terminal/

https://www.chuchur.com/article/windows-terminal-beautify

https://zhuanlan.zhihu.com/p/137595941

https://blog.csdn.net/zaoandly/article/details/106415873

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章