Windows Terminal 美化篇

Windows Terminal 不仅速度快、设计美,还有众多可自定义的 UI 元素、快捷键与实用功能。默认的PowerShell并不美观,仅仅是将原来“傻大黑”变成了“傻大蓝”,所以这次我们来美化它。像MacOS一样使用Windows10 的Terminal。

美化效果


安装终端

直接从Microsoft Store下载安装Windows Terminal

 

安装插件

安装Windows Terminal美化所需的插件

安装Git

点击下方链接,下载对应操作系统的安装包进行安装

 

https://git-scm.com/download/win

安装scoop

安装scoop包管理程序,以管理员运行Terminal输入以下命令安装

 

# 允许本地脚本的执行
set-executionpolicy remotesigned -scope currentuser
# 安装scoop包管理程序
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')

安装choco

安装choco包管理程序,以管理员运行Terminal输入以下命令安装

 

# 安装choco包管理程序
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

安装Oh-my-posh

安装Oh-my-posh主题,以管理员运行Terminal输入以下命令安装

 

# 安装 posh-git
Install-Module posh-git -Scope CurrentUser
# 安装 oh-my-posh
Install-Module oh-my-posh -Scope CurrentUser

安装字体

安装Sarasa Mono T SC字体,一款适用于终端使用的等宽字体

# 安装完之后,在profiles.json文件配置上字体
"profiles": {
    "defaults": {
      ....
      "fontFace": "Sarasa Term SC", //字体
      "fontSize": 14, //文字大小
      ....
    }
}

更改主题

oh-my-posh 内置了10个主题,个人比较喜欢Sorin

 

# Oh-my-posh 已内置了以下10个主题
Agnoster,Avit,Darkblood,Fish,Honukai,Paradox,PowerLine,robbyrussell,Sorin,tehrob
# 查看已安装的主题
Set-Theme ?
# 设置主题或预览主题
Set-Theme Sorin

目录高亮

优化ls命令样式

 

# 安装 ChildItemColor,以管理员执行
Install-Module Get-ChildItemColor -AllowClobber
# 导入 ChildItemColor
Import-Module Get-ChildItemColor

导入配置

让程序启动后自动运行配置文件


# 使用notepad打开profile文件
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE
# 导入oh-my-posh ChildItemColor Theme
Import-Module posh-git
Import-Module oh-my-posh
Import-Module Get-ChildItemColor
Set-Theme Sorin

更改配色

iTerm2-Color-Schemes选择一款自己喜欢的主题配色,之后就可以到仓里下载Windows Terminal格式的主题配色文件。这里提供几个我比较喜欢的主题配色

 


# Afterglow Theme
 {
    "name": "Afterglow",
    "black": "#151515",
    "red": "#ac4142",
    "green": "#7e8e50",
    "yellow": "#e5b567",
    "blue": "#6c99bb",
    "purple": "#9f4e85",
    "cyan": "#7dd6cf",
    "white": "#d0d0d0",
    "brightBlack": "#505050",
    "brightRed": "#ac4142",
    "brightGreen": "#7e8e50",
    "brightYellow": "#e5b567",
    "brightBlue": "#6c99bb",
    "brightPurple": "#9f4e85",
    "brightCyan": "#7dd6cf",
    "brightWhite": "#f5f5f5",
    "background": "#212121",
    "foreground": "#d0d0d0"
},

# Chalk Theme
{
  "name": "Chalk",
  "black": "#7d8b8f",
  "red": "#b23a52",
  "green": "#789b6a",
  "yellow": "#b9ac4a",
  "blue": "#2a7fac",
  "purple": "#bd4f5a",
  "cyan": "#44a799",
  "white": "#d2d8d9",
  "brightBlack": "#888888",
  "brightRed": "#f24840",
  "brightGreen": "#80c470",
  "brightYellow": "#ffeb62",
  "brightBlue": "#4196ff",
  "brightPurple": "#fc5275",
  "brightCyan": "#53cdbd",
  "brightWhite": "#d2d8d9",
  "background": "#2b2d2e",
  "foreground": "#d2d8d9"
}

命令别名

通过在profile中配置alias,可以方便的为其他的命令设置别名,这是个很不错的功能。因为我懒,平时甚至连敲命令也想偷懒,于是,我设置了很多alias

# Remove curl alias
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
# Remove-Item alias:ls -force
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope

function GitLogPretty {
  git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all
}
function GetMyIpv4 {curl -4 ip.sb}
function PrettyLS {colorls --light -A}
function GitStat {git status}
function GoBack {Set-Location ..}
function UpdateScoop {scoop update; scoop update *}
function UpdateChoco {choco upgrade chocolatey}

# Setup other alias
Set-Alias open Invoke-Item
Set-Alias .. GoBack
Set-Alias glola GitLogPretty
Set-Alias gst GitStat
Set-Alias pls PrettyLS
Set-Alias ip GetMyIpv4

配置文件

这是我的profile配置文件,仅供参考。输入notepad $profile打开

Import-Module Get-ChildItemColor

$env:PYTHONIOENCODING="utf-8"
# Remove curl alias
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
# Remove-Item alias:ls -force
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope

function GitLogPretty {
  git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all
}

function PrettyLS {
  colorls --light -A
}

function GitStat {git status}

function GoBack {Set-Location ..}

function GetMyIpv4 {curl -4 ip.sb}

function UpdateScoop {scoop update; scoop update *}

function UpdateChoco {choco upgrade chocolatey}

Import-Module posh-git
Import-Module oh-my-posh
# $DefaultUser = 'spenc'

# Setup other alias
Set-Alias open Invoke-Item
Set-Alias .. GoBack
Set-Alias glola GitLogPretty
Set-Alias gst GitStat
Set-Alias ip GetMyIpv4
Set-Alias pls PrettyLS

# Set theme
Set-Theme robbyrussell

Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

设置文件

这是我的Setting配置文件,仅供参考

 

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",

    // Launch Settings
    "initialCols": 120,
    "initialRows": 30,
    "launchMode": "default",

    // Selection
    "copyOnSelect": false,
    "copyFormatting": true,
    "wordDelimiters": " /\\()\"'-.,:;<>~!@#$%^&*|+=[]{}~?\u2502",

    // Tab UI
    "alwaysShowTabs": true,
    "showTabsInTitlebar": true,
    "showTerminalTitleInTitlebar": true,
    "tabWidthMode": "equal",

    // Miscellaneous
    "confirmCloseAllTabs": true,
    "startOnUserLogin":  false,
    "theme": "dark",
    "rowsToScroll": "dark",
    "snapToGridOnResize": true,

    "profiles":
    {
        "defaults":
        {
            // Put settings here that you want to apply to all profiles.
        },
        "list":
        [
            {
                // Make changes here to the powershell.exe profile.
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "name": "Windows PowerShell",
                "commandline": "powershell.exe",
                "hidden": false,
                "closeOnExit" : true,
                "colorScheme" : "Afterglow",     //颜色主题名称,就是schemes下面的每个实例的 name 值
                "cursorColor" : "#ffffff",           //光标颜色
                "cursorShape" : "filledBox",         //光标类型  可选 bar empytBox filledBox vintage
                "fontFace" : "Sarasa Term SC",       //字体名称  安装字体时的字体名称
                "fontSize" : 12,                     //字体大小
                "historySize" : 8001,
                "icon" : "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",     //程序的小图标,也就是在标题栏和新建中显示的图标地址
                "backgroundImage" : "ms-appx:////Users/Administrator/Pictures/1.png", //配置背景图片地址
                "acrylicOpacity" : 0.75,             //不透明度,值越大,背景就越浓,否则就越淡
                "backgroundImageOpacity": 0.25,      //背景图片的透明度
                "padding" : "0, 0, 0, 0",
                "snapOnInput" : true,
                "startingDirectory" : "%USERPROFILE%",
                "useAcrylic" : true,        //是否开启毛玻璃特效,值为false的时候就没有毛玻璃特效
                "tabTitle" : "Shell"
            },


             {
                "guid": "{18f94f46-96bc-4acb-b9b6-12358eac2124}",
                "name": "Deepin",
                "commandline": "ssh star@192.168.2.174",
                "hidden": false,
                "closeOnExit" : true,
                "colorScheme" : "Afterglow",
                "cursorColor" : "#ffffff",
                "cursorShape" : "filledBox",
                "fontFace" : "Sarasa Term SC",
                "fontSize" : 12,
                "historySize" : 9001,
                "acrylicOpacity" : 0.75,
                "backgroundImageOpacity": 0.25,
                "padding" : "0, 0, 0, 0",
                "snapOnInput" : true,
                "startingDirectory" : "%USERPROFILE%",
                "useAcrylic" : true,
                "tabTitle" : "ssh",
                "backgroundImage" : "ms-appx:////Users/Administrator/Pictures/2.png"
            },

            {
                // Make changes here to the cmd.exe profile.
                "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"
            },
            {
                "guid": "{58ad8b0c-3ef8-5f4d-bc6f-13e4c00f2530}",
                "hidden": false,
                "name": "Debian",
                "source": "Windows.Terminal.Wsl"
            },
            {
                "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
                "hidden": false,
                "name": "Ubuntu",
                "source": "Windows.Terminal.Wsl"
            }
        ]
    },

    // Add custom color schemes to this array.
    // To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
    "schemes": [

            {
              "name": "Chalk",
              "black": "#7d8b8f",
              "red": "#b23a52",
              "green": "#789b6a",
              "yellow": "#b9ac4a",
              "blue": "#2a7fac",
              "purple": "#bd4f5a",
              "cyan": "#44a799",
              "white": "#d2d8d9",
              "brightBlack": "#888888",
              "brightRed": "#f24840",
              "brightGreen": "#80c470",
              "brightYellow": "#ffeb62",
              "brightBlue": "#4196ff",
              "brightPurple": "#fc5275",
              "brightCyan": "#53cdbd",
              "brightWhite": "#d2d8d9",
              "background": "#2b2d2e",
              "foreground": "#d2d8d9"
            },

            {
            "name": "Ubuntu",
            "black": "#2e3436",
            "red": "#cc0000",
            "green": "#4e9a06",
            "yellow": "#c4a000",
            "blue": "#3465a4",
            "purple": "#75507b",
            "cyan": "#06989a",
            "white": "#d3d7cf",
            "brightBlack": "#555753",
            "brightRed": "#ef2929",
            "brightGreen": "#8ae234",
            "brightYellow": "#fce94f",
            "brightBlue": "#729fcf",
            "brightPurple": "#ad7fa8",
            "brightCyan": "#34e2e2",
            "brightWhite": "#eeeeec",
            "background": "#300a24",
            "foreground": "#eeeeec"
            },

            {
              "name": "Afterglow",
              "black": "#151515",
              "red": "#ac4142",
              "green": "#7e8e50",
              "yellow": "#e5b567",
              "blue": "#6c99bb",
              "purple": "#9f4e85",
              "cyan": "#7dd6cf",
              "white": "#d0d0d0",
              "brightBlack": "#505050",
              "brightRed": "#ac4142",
              "brightGreen": "#7e8e50",
              "brightYellow": "#e5b567",
              "brightBlue": "#6c99bb",
              "brightPurple": "#9f4e85",
              "brightCyan": "#7dd6cf",
              "brightWhite": "#f5f5f5",
              "background": "#212121",
              "foreground": "#d0d0d0"
            }

    ],

    // 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" }
    ]
}

文章来源:https://yangwenqing.com/archives/1498/

给TA买糖
共{{data.count}}人
人已赞赏
软件

批量文件修改工具

2020-11-20 0:23:56

LinuxWindows

一键网络重装系统,一键DD– 魔改版

2020-10-22 11:22:14

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索