前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Windows Terminal安装及美化

Windows Terminal安装及美化

作者头像
Naraku
发布2021-07-29 10:52:45
9070
发布2021-07-29 10:52:45
举报
文章被收录于专栏:Naraku的专栏Naraku的专栏

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

安装

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

基本配置

  • 首先打开Windows Terminal终端,点击下三角图标,选择Settings打开配置文件profiles.json
2
2
  • 这里举例配置PowerShellCmd,如需其它终端如GitBash,可参考以下代码自行配置

点击查看配置

代码语言:javascript
复制
"profiles":
[
    {
        // PowerShell
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",  // 唯一ID
        "name": "PowerShell",
        "commandline": "powershell.exe", // 命令行所在位置
        "colorScheme" : "Campbell",      // 主题
        "useAcrylic": true,              // 毛玻璃
        "acrylicOpacity" : 0.8,          // 不透明度
        "fontSize": 10,                  // 字体大小
        "fontFace" : "Consolas",         // 字体
        "cursorShape" : "emptyBox",      // 光标形状,bar/emptyBox/filledBox/underscore/vintage
        "padding": "10, 10, 10, 10",     // 边距
        "closeOnExit": true,             // 关闭时退出终端
        "startingDirectory": "./",       // 当前目录打开
        "historySize": 9001,             // 上滚历史行数
        "hidden": false
    },
    {
        // Command
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "name": "Command",
        "commandline": "cmd.exe",        // 命令行所在位置
        "colorScheme" : "Campbell",      // 主题
        "useAcrylic": true,              // 毛玻璃
        "acrylicOpacity" : 0.8,          // 不透明度
        "fontSize": 10,                  // 字体大小
        "fontFace" : "Consolas",         // 字体
        "cursorShape" : "emptyBox",      // 光标形状,bar/emptyBox/filledBox/underscore/vintage
        "padding": "10, 10, 10, 10",     // 边距
        "closeOnExit": true,             // 关闭时退出终端
        "startingDirectory": "./",       // 当前目录打开
        "hidden": false,
        "historySize": 9001
    }
],

美化

修改字体

  • 推荐字体Fira Code,进入Github仓库,点击上方releases,下载FiraCode_2.zip,下载完成后解压,进入tff文件夹,双击安装即可。
  • 安装完成后,打开配置文件profiles.json,修改字体属性后保存
代码语言:javascript
复制
"profiles":
[
    {
        // PowerShell
        ......
        "fontFace" : "Fira Code",  // 字体
        ......
    }
]

修改配色

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

点击查看配色方案

代码语言:javascript
复制
{
  "name": "rebecca",
  "black": "#12131e",
  "red": "#dd7755",
  "green": "#04dbb5",
  "yellow": "#f2e7b7",
  "blue": "#7aa5ff",
  "purple": "#bf9cf9",
  "cyan": "#56d3c2",
  "white": "#e4e3e9",
  "brightBlack": "#666699",
  "brightRed": "#ff92cd",
  "brightGreen": "#01eac0",
  "brightYellow": "#fffca8",
  "brightBlue": "#69c0fa",
  "brightPurple": "#c17ff8",
  "brightCyan": "#8bfde1",
  "brightWhite": "#f4f2f9",
  "background": "#292a44",
  "foreground": "#e8e6ed"
}
  • 打开配置文件profiles.json,下拉找到schemes列表,将复制的配色方案粘贴进去

点击查看配色方案

代码语言:javascript
复制
"schemes": [
        {
          "name": "rebecca",
          "black": "#12131e",
          "red": "#dd7755",
          "green": "#04dbb5",
          "yellow": "#f2e7b7",
          "blue": "#7aa5ff",
          "purple": "#bf9cf9",
          "cyan": "#56d3c2",
          "white": "#e4e3e9",
          "brightBlack": "#809699",
          "brightRed": "#ff92cd",
          "brightGreen": "#01eac0",
          "brightYellow": "#fffca8",
          "brightBlue": "#69c0fa",
          "brightPurple": "#c17ff8",
          "brightCyan": "#8bfde1",
          "brightWhite": "#f4f2f9",
          "background": "#292a44",
          "foreground": "#e8e6ed"
        }
    ]
  • 最后修改profiles列表中相应终端的colorScheme属性为配色方案中的name

点击查看配置

代码语言:javascript
复制
"profiles":
[
    {
        // PowerShell
        ......
        "colorScheme" : "rebecca",       // 主题
        ......
    }
]

添加Emoji

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

  • 使用管理员模式打开PowerShell,输入以下命令创建配置文件
代码语言:javascript
复制
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
# C:\Users\[用户名]\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  • 安装choco
代码语言:javascript
复制
> iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

# 报错的话应该是Powershell的执行策略问题
> Get-ExecutionPolicy  # 查看当前策略
> Set-ExecutionPolicy Unrestricted  # 设置为Unrestricted
# 等下全部配置完成后,再将执行策略设回前面查看策略时的值(更安全)

> choco                # 测试是否安装成功
  • 使用choco安装ConEmu
代码语言:javascript
复制
> choco install ConEmu
  • 安装oh-my-poshposh-git
代码语言:javascript
复制
> Install-Module posh-git -Scope CurrentUser
> Install-Module oh-my-posh -Scope CurrentUser
> install-module posh-git
  • 打开PowerShell配置文件,如果不知道文件路径可使用$PROFILE查看,打开后插入以下语句
代码语言:javascript
复制
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox  # 设置主题,具体可选主题可看后面
function prompt {"PS $pwd X >" }    # X代表Emoji表情
  • 最后在PowerShell内输入配置文件路径来更新配置并重启PowerShell

随机Emoji

  • 打开oh-my-posh主题配置文件目录
代码语言:javascript
复制
# 主题配置文件目录
C:\Users\[用户名]\Documents\WindowsPowerShell\Modules\oh-my-posh\2.0.332\Themes\ 
  • 选择想修改的主题文件,复制一份重命名为myTheme.psm1,打开myTheme.psm1进行修改
  • 找到以下表示右箭头>的语句,并在其前面加入#进行注释
代码语言:javascript
复制
# $prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor
  • 然后插入以下代码
代码语言:javascript
复制
$food = Get-Random -InputObject ("X","X","X"....)  # X代表Emoji标签
$color = Get-Random -InputObject ("VirtualEnvBackgroundColor", "WithForegroundColor", "GitDefaultColor", "PromptHighlightColor", "PromptBackgroundColor", "WithBackgroundColor")
$prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.$color
$prompt += Write-Prompt -Object "$food "
3
3
  • 最后打开PowerShell配置文件,应用myTheme主题
代码语言:javascript
复制
Set-Theme myTheme  # 设置主题
  • 最终效果
4
4

其它

  • myTheme主题配置
代码语言:javascript
复制
#requires -Version 2 -Modules posh-git

function Write-Theme {
    param(
        [bool]
        $lastCommandFailed,
        [string]
        $with
    )

    $lastColor = $sl.Colors.PromptBackgroundColor
    $prompt = Write-Prompt -Object $sl.PromptSymbols.StartSymbol -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor

    #check the last command state and indicate if failed
    If ($lastCommandFailed) {
        $prompt += Write-Prompt -Object "$($sl.PromptSymbols.FailedCommandSymbol) " -ForegroundColor $sl.Colors.CommandFailedIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
    }

    #check for elevated prompt
    If (Test-Administrator) {
        $prompt += Write-Prompt -Object "$($sl.PromptSymbols.ElevatedSymbol) " -ForegroundColor $sl.Colors.AdminIconForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
    }

    $user = $sl.CurrentUser
    $computer = [System.Environment]::MachineName
    $path = Get-FullPath -dir $pwd
    if (Test-NotDefaultUser($user)) {
        # User@Hostname 
        $prompt += Write-Prompt -Object "$user " -ForegroundColor $sl.Colors.GitDefaultColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
        # $prompt += Write-Prompt -Object "$user@$computer " -ForegroundColor $sl.Colors.SessionInfoForegroundColor -BackgroundColor $sl.Colors.SessionInfoBackgroundColor
    }

    if (Test-VirtualEnv) {
        $prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
        $prompt += Write-Prompt -Object "$($sl.PromptSymbols.VirtualEnvSymbol) $(Get-VirtualEnvName) " -ForegroundColor $sl.Colors.VirtualEnvForegroundColor -BackgroundColor $sl.Colors.VirtualEnvBackgroundColor
        $prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
    }
    else {
        $prompt += Write-Prompt -Object "$($sl.PromptSymbols.SegmentForwardSymbol) " -ForegroundColor $sl.Colors.SessionInfoBackgroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor
    }

    # Writes the drive portion
    $prompt += Write-Prompt -Object "$path " -ForegroundColor $sl.Colors.PromptForegroundColor -BackgroundColor $sl.Colors.PromptBackgroundColor

    $status = Get-VCSStatus
    if ($status) {
        $themeInfo = Get-VcsInfo -status ($status)
        $lastColor = $themeInfo.BackgroundColor
        $prompt += Write-Prompt -Object $($sl.PromptSymbols.SegmentForwardSymbol) -ForegroundColor $sl.Colors.PromptBackgroundColor -BackgroundColor $lastColor
        $prompt += Write-Prompt -Object " $($themeInfo.VcInfo) " -BackgroundColor $lastColor -ForegroundColor $sl.Colors.GitForegroundColor
    }

    # Writes the postfix to the prompt
    $prompt += Write-Prompt -Object $sl.PromptSymbols.SegmentForwardSymbol -ForegroundColor $lastColor

    # Time
    # $timeStamp = Get-Date -UFormat %R
    # $timestamp = "$timeStamp"
    # $prompt += Set-CursorForRightBlockWrite -textLength ($timestamp.Length + 1)     # 一堆空格到行末
    # $prompt += Write-Prompt $timeStamp -ForegroundColor $sl.Colors.GitDefaultColor  # 行末
    # $prompt += Set-Newline  # NewLine

    if ($with) {
        $prompt += Write-Prompt -Object "$($with.ToUpper()) " -BackgroundColor $sl.Colors.WithBackgroundColor -ForegroundColor $sl.Colors.WithForegroundColor
    }

    # $prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.VirtualEnvBackgroundColor
    # $prompt
    
    ######################
    $food = Get-Random -InputObject (“X”,“X”,“X”,“X”,“X”,)
    $color = Get-Random -InputObject ("VirtualEnvBackgroundColor", "WithForegroundColor", "GitDefaultColor", "PromptHighlightColor", "PromptBackgroundColor", "WithBackgroundColor")
    $prompt += Write-Prompt -Object ($sl.PromptSymbols.PromptIndicator) -ForegroundColor $sl.Colors.$color
    $prompt += Write-Prompt -Object "$food "
    ######################

}

$sl = $global:ThemeSettings #local settings
$sl.PromptSymbols.StartSymbol = ''
$sl.PromptSymbols.PromptIndicator = [char]::ConvertFromUtf32(0x276F)
$sl.PromptSymbols.SegmentForwardSymbol = [char]::ConvertFromUtf32(0xE0B0)
$sl.Colors.PromptForegroundColor = [ConsoleColor]::White
$sl.Colors.PromptSymbolColor = [ConsoleColor]::White
$sl.Colors.PromptHighlightColor = [ConsoleColor]::DarkBlue
$sl.Colors.GitForegroundColor = [ConsoleColor]::Black
$sl.Colors.WithForegroundColor = [ConsoleColor]::DarkRed
$sl.Colors.WithBackgroundColor = [ConsoleColor]::Magenta
$sl.Colors.VirtualEnvBackgroundColor = [System.ConsoleColor]::Red
$sl.Colors.VirtualEnvForegroundColor = [System.ConsoleColor]::White

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020 年 01 月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装
  • 基本配置
  • 美化
    • 修改字体
      • 修改配色
        • 添加Emoji
          • 随机Emoji
          • 其它
          相关产品与服务
          命令行工具
          腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档