Windows Terminal是微软出品的新版终端,可扩展性超高,用户可以很大程度的DIY终端外观,比旧版Cmd这个小黑框更好看也更强大。

安装

  • 进入Windosw自带的应用商店搜索Windows Terminal,点击安装即可。也可以根据文档下载Microsoft/Terminal源码自行安装

WindowsTerminal-1

基本配置

  • 首先打开Windows Terminal终端,点击下三角图标,选择Settings打开配置文件profiles.json

WindowsTerminal-2

  • 这里举例配置PowerShellCmd,如需其它终端如GitBash,可参考以下代码自行配置
    1. "profiles":
    2. [
    3. {
    4. // PowerShell
    5. "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", // 唯一ID
    6. "name": "PowerShell",
    7. "commandline": "powershell.exe", // 命令行所在位置
    8. "colorScheme" : "Campbell", // 主题
    9. "useAcrylic": true, // 毛玻璃
    10. "acrylicOpacity" : 0.8, // 不透明度
    11. "fontSize": 10, // 字体大小
    12. "fontFace" : "Consolas", // 字体
    13. "cursorShape" : "emptyBox", // 光标形状,bar/emptyBox/filledBox/underscore/vintage
    14. "padding": "10, 10, 10, 10", // 边距
    15. "closeOnExit": true, // 关闭时退出终端
    16. "startingDirectory": "./", // 当前目录打开
    17. "historySize": 9001, // 上滚历史行数
    18. "hidden": false
    19. },
    20. {
    21. // Command
    22. "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    23. "name": "Command",
    24. "commandline": "cmd.exe", // 命令行所在位置
    25. "colorScheme" : "Campbell", // 主题
    26. "useAcrylic": true, // 毛玻璃
    27. "acrylicOpacity" : 0.8, // 不透明度
    28. "fontSize": 10, // 字体大小
    29. "fontFace" : "Consolas", // 字体
    30. "cursorShape" : "emptyBox", // 光标形状,bar/emptyBox/filledBox/underscore/vintage
    31. "padding": "10, 10, 10, 10", // 边距
    32. "closeOnExit": true, // 关闭时退出终端
    33. "startingDirectory": "./", // 当前目录打开
    34. "hidden": false,
    35. "historySize": 9001
    36. }
    37. ],

美化

修改字体

  • 推荐字体Fira Code,进入Github仓库,点击上方releases,下载FiraCode_2.zip,下载完成后解压,进入tff文件夹,双击安装即可。
  • 安装完成后,打开配置文件profiles.json,修改字体属性后保存

    1. "profiles":
    2. [
    3. {
    4. // PowerShell
    5. ......
    6. "fontFace" : "Fira Code", // 字体
    7. ......
    8. }
    9. ]

    修改配色

  • 打开终端配色开源库iTerm2-Color-Schemes,选择喜欢的配色方案。例如这里选择的是rebecca,在配色库中找到rebecca.json,点击进入,复制配色方案

    1. {
    2. "name": "rebecca",
    3. "black": "#12131e",
    4. "red": "#dd7755",
    5. "green": "#04dbb5",
    6. "yellow": "#f2e7b7",
    7. "blue": "#7aa5ff",
    8. "purple": "#bf9cf9",
    9. "cyan": "#56d3c2",
    10. "white": "#e4e3e9",
    11. "brightBlack": "#666699",
    12. "brightRed": "#ff92cd",
    13. "brightGreen": "#01eac0",
    14. "brightYellow": "#fffca8",
    15. "brightBlue": "#69c0fa",
    16. "brightPurple": "#c17ff8",
    17. "brightCyan": "#8bfde1",
    18. "brightWhite": "#f4f2f9",
    19. "background": "#292a44",
    20. "foreground": "#e8e6ed"
    21. }
  • 打开配置文件profiles.json,下拉找到schemes列表,将复制的配色方案粘贴进去

    1. "schemes": [
    2. {
    3. "name": "rebecca",
    4. "black": "#12131e",
    5. "red": "#dd7755",
    6. "green": "#04dbb5",
    7. "yellow": "#f2e7b7",
    8. "blue": "#7aa5ff",
    9. "purple": "#bf9cf9",
    10. "cyan": "#56d3c2",
    11. "white": "#e4e3e9",
    12. "brightBlack": "#809699",
    13. "brightRed": "#ff92cd",
    14. "brightGreen": "#01eac0",
    15. "brightYellow": "#fffca8",
    16. "brightBlue": "#69c0fa",
    17. "brightPurple": "#c17ff8",
    18. "brightCyan": "#8bfde1",
    19. "brightWhite": "#f4f2f9",
    20. "background": "#292a44",
    21. "foreground": "#e8e6ed"
    22. }
    23. ]
  • 最后修改profiles列表中相应终端的colorScheme属性为配色方案中的name

    1. "profiles":
    2. [
    3. {
    4. // PowerShell
    5. ......
    6. "colorScheme" : "rebecca", // 主题
    7. ......
    8. }
    9. ]

添加Emoji

x> Typecho编辑器好像不支持Emoji,附一个Emoji表情网站,需要请自取

  • 使用管理员模式打开PowerShell,输入以下命令创建配置文件

    1. if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
    2. # C:\Users\[用户名]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  • 安装choco ```powershell

    iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

报错的话应该是Powershell的执行策略问题

Get-ExecutionPolicy # 查看当前策略 Set-ExecutionPolicy Unrestricted # 设置为Unrestricted

等下全部配置完成后,再将执行策略设回前面查看策略时的值(更安全)

choco # 测试是否安装成功

  1. - 使用`choco`安装`ConEmu`
  2. ```powershell
  3. > choco install ConEmu
  • 安装oh-my-poshposh-git

    1. > Install-Module posh-git -Scope CurrentUser
    2. > Install-Module oh-my-posh -Scope CurrentUser
    3. > install-module posh-git
  • 打开PowerShell配置文件,如果不知道文件路径可使用$PROFILE查看,打开后插入以下语句

    1. Import-Module posh-git
    2. Import-Module oh-my-posh
    3. Set-Theme Paradox # 设置主题,具体可选主题可看后面
    4. function prompt {"PS $pwd X >" } # X代表Emoji表情
  • 最后在PowerShell内输入配置文件路径来更新配置并重启PowerShell

    随机Emoji

  • 打开oh-my-posh主题配置文件目录

    1. # 主题配置文件目录
    2. C:\Users\[用户名]\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.332\Themes\
  • 选择想修改的主题文件,复制一份重命名为myTheme.psm1,打开myTheme.psm1进行修改

  • 找到以下表示右箭头>的语句,并在其前面加入#进行注释

    1. # $prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor
  • 然后插入以下代码

    1. $food = Get-Random -InputObject ("X","X","X"....) # X代表Emoji标签
    2. $color = Get-Random -InputObject ("VirtualEnvBackgroundColor", "WithForegroundColor", "GitDefaultColor", "PromptHighlightColor", "PromptBackgroundColor", "WithBackgroundColor")
    3. $prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.$color
    4. $prompt += Write-Prompt -Object "$food "

WindowsTerminal-3

  • 最后打开PowerShell配置文件,应用myTheme主题

    1. Set-Theme myTheme # 设置主题
  • 最终效果

WindowsTerminal-4

其它

  • myTheme主题配置

[hide]

  1. #requires -Version 2 -Modules posh-git
  2. function Write-Theme {
  3. param(
  4. [bool]
  5. $lastCommandFailed,
  6. [string]
  7. $with
  8. )
  9. $lastColor = $sl.Colors.PromptBackgroundColor
  10. $prompt = Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
  11. #check the last command state and indicate if failed
  12. If ($lastCommandFailed) {
  13. $prompt += Write-Prompt -Object "$($sl.PromptSymbols.FailedCommandSymbol) " -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
  14. }
  15. #check for elevated prompt
  16. If (Test-Administrator) {
  17. $prompt += Write-Prompt -Object "$($sl.PromptSymbols.ElevatedSymbol) " -ForegroundColor $sl.Colors.AdminIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
  18. }
  19. $user = $sl.CurrentUser
  20. $computer = [System.Environment]::MachineName
  21. $path = Get-FullPath -dir $pwd
  22. if (Test-NotDefaultUser($user)) {
  23. # User@Hostname
  24. $prompt += Write-Prompt -Object "$user " -ForegroundColor $sl.Colors.GitDefaultColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
  25. # $prompt += Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
  26. }
  27. if (Test-VirtualEnv) {
  28. $prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
  29. $prompt += Write-Prompt -Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
  30. $prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
  31. }
  32. else {
  33. $prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
  34. }
  35. # Writes the drive portion
  36. $prompt += Write-Prompt -Object "$path " -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
  37. $status = Get-VCSStatus
  38. if ($status) {
  39. $themeInfo = Get-VcsInfo -status ($status)
  40. $lastColor = $themeInfo.BackgroundColor
  41. $prompt += Write-Prompt -Object $($sl.PromptSymbols.SegmentForwardSymbol) -ForegroundColor $sl.Colors.PromptBackgroundColor -BackgroundColor $lastColor
  42. $prompt += Write-Prompt -Object " $($themeInfo.VcInfo) " -BackgroundColor $lastColor -ForegroundColor $sl.Colors.GitForegroundColor
  43. }
  44. # Writes the postfix to the prompt
  45. $prompt += Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor
  46. # Time
  47. # $timeStamp = Get-Date -UFormat %R
  48. # $timestamp = "$timeStamp"
  49. # $prompt += Set-CursorForRightBlockWrite -textLength ($timestamp.Length + 1) # 一堆空格到行末
  50. # $prompt += Write-Prompt $timeStamp -ForegroundColor $sl.Colors.GitDefaultColor # 行末
  51. # $prompt += Set-Newline # NewLine
  52. if ($with) {
  53. $prompt += Write-Prompt -Object "$($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
  54. }
  55. # $prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor
  56. # $prompt
  57. ######################
  58. $food = Get-Random -InputObject (“X”,“X”,“X”,“X”,“X”,)
  59. $color = Get-Random -InputObject ("VirtualEnvBackgroundColor", "WithForegroundColor", "GitDefaultColor", "PromptHighlightColor", "PromptBackgroundColor", "WithBackgroundColor")
  60. $prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.$color
  61. $prompt += Write-Prompt -Object "$food "
  62. ######################
  63. }
  64. $sl = $global:ThemeSettings #local settings
  65. $sl.PromptSymbols.StartSymbol = ''
  66. $sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x276F)
  67. $sl.PromptSymbols.SegmentForwardSymbol = [char]::ConvertFromUtf32(0xE0B0)
  68. $sl.Colors.PromptForegroundColor = [ConsoleColor]::White
  69. $sl.Colors.PromptSymbolColor = [ConsoleColor]::White
  70. $sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue
  71. $sl.Colors.GitForegroundColor = [ConsoleColor]::Black
  72. $sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRed
  73. $sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta
  74. $sl.Colors.VirtualEnvBackgroundColor = [System.ConsoleColor]::Red
  75. $sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::White

[/hide]